package com.sxfq.loansupermarket.backsystem.modular.doctorLooked.controller;

import com.aliyun.oss.OSSClient;
import com.aliyun.oss.model.OSSObject;
import com.aliyun.oss.model.CopyObjectResult;
import com.baomidou.mybatisplus.plugins.Page;
import com.sxfq.loansupermarket.backsystem.common.constant.factory.PageFactory;
import com.sxfq.loansupermarket.backsystem.common.constant.tips.Tip;
import com.sxfq.loansupermarket.backsystem.common.controller.BaseController;
import com.sxfq.loansupermarket.backsystem.common.exception.BizExceptionEnum;
import com.sxfq.loansupermarket.backsystem.common.exception.BussinessException;
import com.sxfq.loansupermarket.backsystem.common.persistence.model.Dept;
import com.sxfq.loansupermarket.backsystem.common.persistence.model.Role;
import com.sxfq.loansupermarket.backsystem.common.persistence.model.User;
import com.sxfq.loansupermarket.backsystem.core.log.LogManager;
import com.sxfq.loansupermarket.backsystem.core.log.factory.LogTaskFactory;
import com.sxfq.loansupermarket.backsystem.core.shiro.ShiroKit;
import com.sxfq.loansupermarket.backsystem.core.support.DateTimeKit;
import com.sxfq.loansupermarket.backsystem.core.support.HttpKit;
import com.sxfq.loansupermarket.backsystem.core.util.*;
import com.sxfq.loansupermarket.backsystem.modular.IntegralMall.entity.MembersUser;
import com.sxfq.loansupermarket.backsystem.modular.arrival.entity.ApprovalProcessInfo;
import com.sxfq.loansupermarket.backsystem.modular.arrival.entity.CustomerInfo;
import com.sxfq.loansupermarket.backsystem.modular.arrival.entity.FirstCustomerInfo;
import com.sxfq.loansupermarket.backsystem.modular.arrival.entity.ScoreDealInfo;
import com.sxfq.loansupermarket.backsystem.modular.arrival.service.ICustomerPublicService;
import com.sxfq.loansupermarket.backsystem.modular.arrival.service.ICustomerService;
import com.sxfq.loansupermarket.backsystem.modular.base.SqlMapper;
import com.sxfq.loansupermarket.backsystem.modular.basicData.entity.DoctorInfo;
import com.sxfq.loansupermarket.backsystem.modular.basicData.entity.PayServicedInfo;
import com.sxfq.loansupermarket.backsystem.modular.basicData.entity.RefereeShipInfo;
import com.sxfq.loansupermarket.backsystem.modular.basicData.entity.TcInfo;
import com.sxfq.loansupermarket.backsystem.modular.doctorLooked.entity.*;
import com.sxfq.loansupermarket.backsystem.modular.doctorLooked.service.IDoctorLookedService;
import com.sxfq.loansupermarket.backsystem.modular.logsf.entity.CustomerReservationsUpdateLogInfo;
import com.sxfq.loansupermarket.backsystem.modular.logsf.entity.DoctorDailyLog;
import com.sxfq.loansupermarket.backsystem.modular.logsf.entity.SearchCustomerReservationsUpdateLogInfo;
import com.sxfq.loansupermarket.backsystem.modular.logsf.entity.SearchDoctorDailyLog;
import com.sxfq.loansupermarket.backsystem.modular.logsf.service.ICustomerStatusLogService;
import com.sxfq.loansupermarket.backsystem.modular.marketing.entity.ReservationsInfo;
import com.sxfq.loansupermarket.backsystem.modular.marketing.service.IReservationsService;
import com.sxfq.loansupermarket.backsystem.modular.qualityAssurance.entity.QualityAssuranceInfo;
import com.sxfq.loansupermarket.backsystem.modular.qualityAssurance.entity.RootImageInfo;
import com.sxfq.loansupermarket.backsystem.modular.tcCenter.entity.ConsultantInfo;
import com.sxfq.loansupermarket.backsystem.modular.tcCenter.entity.DepartmentInfo;
import com.sxfq.loansupermarket.backsystem.modular.tcCenter.service.IConsultantService;
import com.sxfq.loansupermarket.backsystem.modular.websocket.WebSocket;
import com.sxfq.loansupermarket.backsystem.modular.weixin.config.MemberEnumConfig;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.*;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 医生看诊/update
 *
 * @author py
 * @Date 2018年4月19日23:15:54
 */
@Controller
@RequestMapping("/doctorLooked")
public class DoctorLookedController extends BaseController {
    @Autowired
    IDoctorLookedService service;

    @Autowired
    IConsultantService consultantService;

    @Autowired
    ICustomerService customerService;

    @Autowired
    ICustomerPublicService customerPublicService;

    @Autowired
    ICustomerStatusLogService statusLogService;

    @Autowired
    IReservationsService reservationsService;

    @Autowired
    private SqlMapper sqlMapper;

    @Autowired
    AliyunOssUtil aliyunOssUtil;

    @Autowired
    WebSocket webSocket;

    private String PREFIX = "/doctorLooked/";

    private String PREFIX1 = "/weixin/doctor/";
    //文件存储目录
    private String filedir = "photo/";

    /**
     * 微信
     * 跳转到医生日程
     */
    @RequestMapping("/doctor_schedule")
    public String doctor_schedule(Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        return PREFIX1 + "doctor_schedule.html";
    }

    /**
     * 微信
     * 跳转到医生随访
     */
    @RequestMapping("/doctor_followUpWx")
    public String doctor_followUpWx(Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        return PREFIX1 + "doctor_followUpWx.html";
    }

    /**
     * 微信
     * 跳转到医生患者
     */
    @RequestMapping("/doctor_patient")
    public String doctor_patient(Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        return PREFIX1 + "doctor_patient.html";
    }

    /**
     * 微信
     * 跳转到医生业绩
     */
    @RequestMapping("/doctor_achievement")
    public String doctor_achievement(Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        return PREFIX1 + "doctor_achievement.html";
    }

    /**
     * 微信
     * 跳转到医生新建预约
     */
    @RequestMapping("/doctor_addAppointment/{pageNumber}")
    public String doctor_addAppointment(@PathVariable String pageNumber, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        model.addAttribute("pageNumber", pageNumber);
        return PREFIX1 + "doctor_addAppointment.html";
    }

    /**
     * 微信
     * 跳转到医生随访详情
     */
    @RequestMapping("/doctor_fullowDetails/{pageNumber}")
    public String doctor_fullowDetails(@PathVariable String pageNumber, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        model.addAttribute("pageNumber", pageNumber);
        return PREFIX1 + "doctor_fullowDetails.html";
    }

    /**
     * 微信
     * 跳转到医生新建患者
     */
    @RequestMapping("/doctor_addPatient")
    public String doctor_addPatient(Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        return PREFIX1 + "doctor_addPatient.html";
    }

    /**
     * 微信
     * 跳转到医生患者详情
     */
    @RequestMapping("/doctor_patientDetails")
    public String doctor_patientDetails(Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        return PREFIX1 + "doctor_patientDetails.html";
    }

    /**
     * 微信
     * 跳转到医生添加病历
     */
    @RequestMapping("/doctor_medicalRecord")
    public String doctor_medicalRecord(Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        return PREFIX1 + "doctor_medicalRecord.html";
    }

    /**
     * 微信
     * 跳转到医生上传影像
     */
    @RequestMapping("/doctor_uploadImage")
    public String doctor_uploadImage(Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        return PREFIX1 + "doctor_uploadImage.html";
    }

    /**
     * 微信
     * 跳转到医生牙位选项页面
     */
    @RequestMapping("/doctor_toothOption")
    public String doctor_toothOption(Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        return PREFIX1 + "doctor_toothOption.html";
    }


//    -------------------   分割线  -----------------------

    /**
     * 跳转到医生看诊
     */
    @RequestMapping("")
    public String consultant(Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        if (ShiroKit.getUser().getDoctorInfoList() == null) {
            String doctorListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + ShiroKit.getUser().getAbbreviation() + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            List<DoctorInfo> doctorInfoList=sqlMapper.selectList(doctorListSql,DoctorInfo.class);
            ShiroKit.getUser().setDoctorInfoList(doctorInfoList);
        }
        model.addAttribute("doctorList", ShiroKit.getUser().getDoctorInfoList());
        model.addAttribute("user", ShiroKit.getUser().getAccount());
        return PREFIX + "new_doctor_looked.html";
    }

    /**
     * 跳转到医生回访
     */
    @RequestMapping("/doctor_visit")
    public String doctor_visit(Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        if (ShiroKit.getUser().getDoctorInfoList() == null) {
            String doctorListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + ShiroKit.getUser().getAbbreviation() + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            List<DoctorInfo> doctorInfoList=sqlMapper.selectList(doctorListSql,DoctorInfo.class);
            ShiroKit.getUser().setDoctorInfoList(doctorInfoList);
        }
        model.addAttribute("doctorList", ShiroKit.getUser().getDoctorInfoList());
        model.addAttribute("loginName", ShiroKit.getUser().getAccount());
        return PREFIX + "doctor_revisit.html";
    }

    /**
     * 跳转到前台回访
     */
    @RequestMapping("/doctor_visits")
    public String doctor_visits(Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        if (ShiroKit.getUser().getDoctorInfoList() == null) {
            String doctorListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + ShiroKit.getUser().getAbbreviation() + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            List<DoctorInfo> doctorInfoList=sqlMapper.selectList(doctorListSql,DoctorInfo.class);
            ShiroKit.getUser().setDoctorInfoList(doctorInfoList);
        }
        model.addAttribute("doctorList", ShiroKit.getUser().getDoctorInfoList());
        model.addAttribute("loginName", ShiroKit.getUser().getAccount());
        return PREFIX + "doctor_revisits.html";
    }

    @RequestMapping(value = "/case_import")
    public String to_import(Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        return PREFIX + "case_import.html";
    }

    @RequestMapping(value = "/return_import")
    public String return_import(Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        return PREFIX + "return_import.html";
    }

    /**
     * 跳转到医生划价预览界面
     */
    @RequestMapping("/charge_price")
    public String doctorChangePrice(Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        if (ShiroKit.getUser().getDoctorInfoList() == null) {
            String doctorListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + ShiroKit.getUser().getAbbreviation() + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            List<DoctorInfo> doctorInfoList=sqlMapper.selectList(doctorListSql,DoctorInfo.class);
            ShiroKit.getUser().setDoctorInfoList(doctorInfoList);
        }
        model.addAttribute("doctorList", ShiroKit.getUser().getDoctorInfoList());
        return PREFIX + "doctor_charge_price.html";
    }

    /**
     * 跳转到 医生业绩查询界面
     */
    @RequestMapping("/query_performance")
    public String queryPerformance(Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        if (ShiroKit.getUser().getTcList() == null) {
            String getListSql = " select a.id as id,a.account as tcName from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on a.roleid=c.id " +
                    " where b.abbreviation='"+tableHead+"' and c.name like CONCAT('%','tc','%') ";
            List<TcInfo> tcList =sqlMapper.selectList(getListSql,TcInfo.class);
            ShiroKit.getUser().setTcList(tcList);
        }
        if (ShiroKit.getUser().getDoctorInfoList() == null) {
            String doctorListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + ShiroKit.getUser().getAbbreviation() + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            List<DoctorInfo> doctorInfoList=sqlMapper.selectList(doctorListSql,DoctorInfo.class);
            ShiroKit.getUser().setDoctorInfoList(doctorInfoList);
        }
        if (ShiroKit.getUser().getDepartmentList() == null) {
            String getListSql = "select a.department as department from " + ShiroKit.getUser().getPay_service_grade_info() + " a where a.is_upper=1 group by a.department order by a.id;";
            List<DepartmentInfo> departmentList=sqlMapper.selectList(getListSql,DepartmentInfo.class);
            ShiroKit.getUser().setDepartmentList(departmentList);
        }
        model.addAttribute("outpatientManagementList", ShiroKit.getSessionAttr("outpatientManagementList"));
        model.addAttribute("tcList", ShiroKit.getUser().getTcList());
        model.addAttribute("doctorList", ShiroKit.getUser().getDoctorInfoList());
        model.addAttribute("departmentList",ShiroKit.getUser().getDepartmentList());
        model.addAttribute("sttleAccountsTime", ShiroKit.getUser().getSttleAccountsTime());
        return PREFIX + "doctor_query_performance.html";
    }

    /**
     * 再预约
     */
    @RequestMapping("/doctor_appointment/{cid}")
    public String doctor_appointment(@PathVariable String cid, Model model) {
        String customerId = cid.split(",")[0];
        String doctor = cid.split(",")[2];
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        String sql = "select * from " + ShiroKit.getUser().getCustomer_info() + " where id='" + customerId + "' limit 1";
        CustomerInfo customerInfo = sqlMapper.selectOne(sql, CustomerInfo.class);
        if (ShiroKit.getUser().getTcList() == null) {
            String getListSql = " select a.id as id,a.account as tcName from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on a.roleid=c.id " +
                    " where b.abbreviation='"+tableHead+"' and c.name like CONCAT('%','tc','%') ";
            List<TcInfo> tcList =sqlMapper.selectList(getListSql,TcInfo.class);
            ShiroKit.getUser().setTcList(tcList);
        }
        if (ShiroKit.getUser().getDoctorInfoList() == null) {
            String doctorListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + ShiroKit.getUser().getAbbreviation() + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            List<DoctorInfo> doctorInfoList=sqlMapper.selectList(doctorListSql,DoctorInfo.class);
            ShiroKit.getUser().setDoctorInfoList(doctorInfoList);
        }
        if (ShiroKit.getUser().getDepartmentList() == null) {
            String getListSql = "select a.department as department from " + ShiroKit.getUser().getPay_service_grade_info() + " a where a.is_upper=1 group by a.department order by a.id;";
            List<DepartmentInfo> departmentList=sqlMapper.selectList(getListSql,DepartmentInfo.class);
            ShiroKit.getUser().setDepartmentList(departmentList);
        }
        model.addAttribute("doctorList", ShiroKit.getUser().getDoctorInfoList());
        model.addAttribute("departmentList",ShiroKit.getUser().getDepartmentList());
        model.addAttribute("tcList", ShiroKit.getUser().getTcList());
        model.addAttribute("doctor", doctor);
        model.addAttribute("customerInfo", customerInfo);
        return PREFIX + "doctor_appointment.html";
    }

    /**
     * 跳转到医生今日操作
     */
    @RequestMapping("/operation")
    public String doctorOperation(Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        model.addAttribute("loginName", ShiroKit.getUser().getAccount());
        return PREFIX + "doctor_operation.html";
    }

    /**
     * 删除牙体牙髓病例
     */
    @RequestMapping(value = "/deleteOperationRecords/{id}")
    @ResponseBody
    public Tip deleteOperationRecords(@PathVariable String id) throws Exception {
        service.deleteOperationRecords(id);
        return SUCCESS_TIP;
    }

    /**
     * 跳转到医生再随访
     */
    @RequestMapping("/doctor_followUp")
    public String doctor_followUp(Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        return PREFIX + "doctor_followUp.html";
    }

    /**
     * 修改中 在随访
     */
    @RequestMapping("/doctor_followUp1")
    public String doctor_followUp1(Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        return PREFIX + "doctor_followUp1.html";
    }

    /**
     * 统计医生收费金额
     */
    @RequestMapping(value = "/totalMoney", method = RequestMethod.GET)
    @ResponseBody
    public double totalMoney(String reach, String payServiceName, String startTime, String endTime) throws Exception {
        String sqltj = "";
        if (StringUtils.isNotBlank(startTime)) {
            sqltj += " and  t.operation_time >= '" + startTime + "' ";
        }
        if (StringUtils.isNotBlank(endTime)) {
            sqltj += " and  t.operation_time <= '" + endTime + "' ";
        }
        if (StringUtils.isNotBlank(payServiceName)) {
            sqltj += " and  t1.pay_service_name like CONCAT('%" + payServiceName + "%') ";
        }
        String sql2 = "select b.id as roleid from user a left join role b on a.roleId=b.id where a.account='" + ShiroKit.getUser().getAccount() + "' limit 1";
        User user = sqlMapper.selectOne(sql2, User.class);
        if (user != null) {
            if ("1".equals(user.getRoleid()) || "1,".equals(user.getRoleid().substring(0, 2))) {
                if (StringUtils.isNotBlank(reach)) {
                    sqltj += "  and  t.doctor = '" + reach + "' ";
                } else {
                    sqltj += " ";
                }
            } else {
                sqltj += " and t.doctor = '" + ShiroKit.getUser().getAccount() + "' ";
            }
        }
        String sql = "select sum(t4.serviceActualPay) serviceActualPay from( select sum(t3.serviceActualPay) as serviceActualPay, sum(t3.foldingPay) as foldingPay,t3.id,t3.id2,t3.doctor, t3.payServiceName,sum(t3.payServiceNum) as payServiceNum " +
                " from  (select sum(t.service_actual_pay) as serviceActualPay, t.folding_pay as foldingPay ,t.id as id, t.id2 as id2,t.doctor as doctor, " +
                " t1.pay_service_name as payServiceName,t.pay_service_num as payServiceNum,t.pay_service_id as payServiceId from " + ShiroKit.getUser().getDeal_info() + " t " +
                " left join " + ShiroKit.getUser().getPay_service_info() + " t1 on t.pay_service_id=t1.id " +
                " left join " + ShiroKit.getUser().getCustomer_info() + " t2 on t.customer_id=t2.id where t.deal_status='已结账' " + sqltj +
                " group by t.id2 order by t.operation_time) t3 group by t3.payServiceId ) t4 limit 1";
        PayServicedInfo searchInfo = sqlMapper.selectOne(sql, PayServicedInfo.class);
        return searchInfo.getServiceActualPay();
    }

    /**
     * 统计查询
     */
    @RequestMapping(value = "/alltotal", method = RequestMethod.GET)
    @ResponseBody
    public List<DoctorLookedInfo> alltotal(String reach, String startTime, String endTime,
                                           String executeStatus, String doctor) throws Exception {
        String contitionInfo = "";
        if (StringUtils.isNotBlank(reach)) {
            contitionInfo += "   and (t2.customer_name like CONCAT('%','" + reach + "','%') or t2.customer_phone like CONCAT('%','" + reach + "','%') or " +
                    "     t2.wechat_number like CONCAT('%','" + reach + "','%') or t2.medical_record_number like CONCAT('%','" + reach + "','%') " +
                    "     or t2.szm like CONCAT('%','" + reach + "','%'))";
        }
        if (StringUtils.isNotBlank(startTime)) {
            contitionInfo += "  and  t.create_time  >= '" + startTime + "' ";
        }
        if (StringUtils.isNotBlank(endTime)) {
            contitionInfo += "  and  t.create_time  <= '" + endTime + "' ";
        }
        if (StringUtils.isNotBlank(executeStatus)) {
            contitionInfo += " and  t.execute_status  = '" + executeStatus + "' ";
        }
        if (StringUtils.isNotBlank(doctor)) {
            contitionInfo += " and  t.doctor  = '" + doctor + "' ";
        }
        String sql = "select count(1) as countNum from doctor_change_price t left join " + ShiroKit.getUser().getDeal_info() + " t1 on t.id2=t1.id2 " +
                " left join " + ShiroKit.getUser().getCustomer_info() + " t2 on t1.customer_id=t2.id " +
                " where t1.deal_status='已结账' " + contitionInfo + " group by t2.reservations_id";
        List<DoctorLookedInfo> tongJiInfoList1 = sqlMapper.selectList(sql, DoctorLookedInfo.class);
        return tongJiInfoList1;
    }

    /**
     * 跳转到医生排班
     */
    @RequestMapping("/doctor_scheduling")
    public String doctor_scheduling(Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        return PREFIX + "doctor_scheduling.html";
    }

    /**
     * 跳转到医生排班
     */
    @RequestMapping("/doctor_preview")
    public String doctor_preview(Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        return PREFIX + "doctor_preview.html";
    }

    /**
     * 跳转到预约客户
     */
    @RequestMapping("/doctor_addTask/{eventData}")
    public String doctor_addTask(@PathVariable String eventData, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        String startTime = eventData.split(",")[0];
        String endTime = eventData.split(",")[1];
        String doctor = eventData.split(",")[2];
        String continued = eventData.split(",")[3];
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        if (ShiroKit.getUser().getTcList() == null) {
            String getListSql = " select a.id as id,a.account as tcName from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on a.roleid=c.id " +
                    " where b.abbreviation='"+tableHead+"' and c.name like CONCAT('%','tc','%') ";
            List<TcInfo> tcList =sqlMapper.selectList(getListSql,TcInfo.class);
            ShiroKit.getUser().setTcList(tcList);
        }
        if (ShiroKit.getUser().getDoctorInfoList() == null) {
            String doctorListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + ShiroKit.getUser().getAbbreviation() + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            List<DoctorInfo> doctorInfoList=sqlMapper.selectList(doctorListSql,DoctorInfo.class);
            ShiroKit.getUser().setDoctorInfoList(doctorInfoList);
        }
        model.addAttribute("doctorList", ShiroKit.getUser().getDoctorInfoList());
        if (ShiroKit.getUser().getDepartmentList() == null) {
            String getListSql = "select a.department as department from " + ShiroKit.getUser().getPay_service_grade_info() + " a where a.is_upper=1 group by a.department order by a.id;";
            List<DepartmentInfo> departmentList=sqlMapper.selectList(getListSql,DepartmentInfo.class);
            ShiroKit.getUser().setDepartmentList(departmentList);
        }
        model.addAttribute("departmentList",ShiroKit.getUser().getDepartmentList());
        model.addAttribute("tcList", ShiroKit.getUser().getTcList());
        model.addAttribute("startTime", startTime);
        model.addAttribute("endTime", endTime);
        model.addAttribute("doctor", doctor);
        model.addAttribute("continued", continued);
        return PREFIX + "doctor_addTask.html";
    }

    /**
     * 跳转到新建临时患者
     */
    @RequestMapping("/temporaryAppointment")
    public String temporaryAppointment(Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        if (ShiroKit.getUser().getRefereeShipInfoList() == null) {
            String getListSql = "select id,referee_ship as refereeShip from referee_ship_info order by num asc;";
            List<RefereeShipInfo> refereeShipList = sqlMapper.selectList(getListSql, RefereeShipInfo.class);
            ShiroKit.getUser().setRefereeShipInfoList(refereeShipList);
        }
        model.addAttribute("refereeShipList", ShiroKit.getUser().getRefereeShipInfoList());
        return PREFIX + "temporaryAppointment.html";
    }

    /**
     * 跳转到预约客户
     */
    @RequestMapping("/doctor_addTaskMarket/{eventData}")
    public String doctor_addTaskMarket(@PathVariable String eventData, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        String startTime = eventData.split(",")[0];
        String endTime = eventData.split(",")[1];
        String doctor = eventData.split(",")[2];
        String continued = eventData.split(",")[3];
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        if (ShiroKit.getUser().getTcList() == null) {
            String getListSql = " select a.id as id,a.account as tcName from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on a.roleid=c.id " +
                    " where b.abbreviation='"+tableHead+"' and c.name like CONCAT('%','tc','%') ";
            List<TcInfo> tcList =sqlMapper.selectList(getListSql,TcInfo.class);
            ShiroKit.getUser().setTcList(tcList);
        }
        if (ShiroKit.getSessionAttr("jysList") == null) {
            String sql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + tableHead + "' and c.name='洁牙师' and b.simplename= '" + ShiroKit.getUser().getOutpatientName() + "'";
            ShiroKit.setSessionAttr("jysList", sqlMapper.selectList(sql));
        }
        if (ShiroKit.getUser().getDepartmentList() == null) {
            String getListSql = "select a.department as department from " + ShiroKit.getUser().getPay_service_grade_info() + " a where a.is_upper=1 group by a.department order by a.id;";
            List<DepartmentInfo> departmentList=sqlMapper.selectList(getListSql,DepartmentInfo.class);
            ShiroKit.getUser().setDepartmentList(departmentList);
        }
        model.addAttribute("departmentList",ShiroKit.getUser().getDepartmentList());
        model.addAttribute("jysList", ShiroKit.getSessionAttr("jysList"));
        model.addAttribute("tcList", ShiroKit.getUser().getTcList());
        model.addAttribute("startTime", startTime);
        model.addAttribute("endTime", endTime);
        model.addAttribute("doctor", doctor);
        model.addAttribute("continued", continued);
        return PREFIX + "doctor_addTaskMarket.html";
    }

    /**
     * 跳转到修改预约客户
     */
    @RequestMapping("/doctor_addTasks/{ids}")
    public String doctor_addTasks(@PathVariable String ids, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        String sql = "select left(t.start_time,19) as startTime," +
                "( " +
                " CASE t.customer_sex " +
                " WHEN 1 THEN " +
                " '男' " +
                " WHEN 2 THEN " +
                " '女' " +
                " ELSE " +
                " '未知' " +
                " END " +
                " ) as sex ,t.* " +
                " from " + ShiroKit.getUser().getCustomer_info() + " t " +
                " where (arrival_status=1 or arrival_status=6 or arrival_status=7 " +
                " or arrival_status=9 or arrival_status=10) and t.id='" + ids + "' " +
                " order by arrival_time desc limit 0,1";
        ConsultantInfo consultantInfo = sqlMapper.selectOne(sql, ConsultantInfo.class);
        if (ShiroKit.getUser().getDepartmentList() == null) {
            String getListSql = "select a.department as department from " + ShiroKit.getUser().getPay_service_grade_info() + " a where a.is_upper=1 group by a.department order by a.id;";
            List<DepartmentInfo> departmentList=sqlMapper.selectList(getListSql,DepartmentInfo.class);
            ShiroKit.getUser().setDepartmentList(departmentList);
        }
        if (ShiroKit.getUser().getTcList() == null) {
            String getListSql = " select a.id as id,a.account as tcName from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on a.roleid=c.id " +
                    " where b.abbreviation='"+tableHead+"' and c.name like CONCAT('%','tc','%') ";
            List<TcInfo> tcList =sqlMapper.selectList(getListSql,TcInfo.class);
            ShiroKit.getUser().setTcList(tcList);
        }
        if (ShiroKit.getUser().getDoctorInfoList() == null) {
            String doctorListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + ShiroKit.getUser().getAbbreviation() + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            List<DoctorInfo> doctorInfoList=sqlMapper.selectList(doctorListSql,DoctorInfo.class);
            ShiroKit.getUser().setDoctorInfoList(doctorInfoList);
        }
        model.addAttribute("doctorList", ShiroKit.getUser().getDoctorInfoList());
        if (StringUtil.isNotEmpty(consultantInfo.getAppointmentPayService())) {
            String payService = consultantInfo.getAppointmentPayService().substring(0, consultantInfo.getAppointmentPayService().length() - 1);
            model.addAttribute("payService", payService);
        } else {
            model.addAttribute("payService", "");
        }
        model.addAttribute("tcList", ShiroKit.getUser().getTcList());
        model.addAttribute("departmentList",ShiroKit.getUser().getDepartmentList());
        model.addAttribute("consultantInfo", consultantInfo);
        model.addAttribute("customerId", ids);
        return PREFIX + "doctor_addTasks.html";
    }

    /**
     * 通过 ID 查看预约患者信息
     */
    @RequestMapping("/doctor_display/{sid}")
    public String doctor_display(@PathVariable String sid, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        String startTime = sid.split(",")[0];
        String id = sid.split(",")[1];
        String endTime = sid.split(",")[2];
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        String sql = "select * from " + ShiroKit.getUser().getCustomer_info() + " t" +
                " where t.arrival_status!=8 and t.id='" + id + "' limit 1";
        CustomerInfo customerInfo = sqlMapper.selectOne(sql, CustomerInfo.class);
        model.addAttribute("startTime", startTime);
        model.addAttribute("endTime", endTime);
        model.addAttribute("customerInfo", customerInfo);
        return PREFIX + "doctor_display.html";
    }

    /**
     * 跳转到医生收费明细
     */
    @RequestMapping("/charge_schedule")
    public String charge_schedule(Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        return PREFIX + "charge_schedule.html";
    }

    /**
     * 医生划价预览表格
     */
    @RequestMapping("/getDoctorChargePrice")
    @ResponseBody
    public Object getDoctorChargePrice(SearchDoctorLookedInfo info, HttpServletRequest request) {
        Page<DoctorLookedInfo> page = new PageFactory<DoctorLookedInfo>().defaultPage();
        try {
            List<DoctorLookedInfo> list = service.selectDoctorChargePrice(page, info);
            page.setRecords(list);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return super.packForBT(page);
    }

    /**
     * 跳转到打印信息shortMessage
     */
    @RequestMapping("/printingAppointment/{customerId}")
    public String printingAppointment(@PathVariable String customerId, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        String sql = " select id as id,reservations_id as reservationsId, medical_record_number as medicalRecordNumber,medical_reasons as medicalReasons,select_reasons as selectReasons,yellow_number as yellowNumber, " +
                " arrival_store as arrivalStore,customer_name as customerName,customer_age as customerAge,occupation as occupation," +
                "one_medium as oneMedium ,two_medium as twoMedium,thr_medium as thrMedium,one_channel as oneChannel,two_channel as twoChannel ,thr_channel as thrChannel," +
                "  email as email , wechat_number as wechatNumber ,region as region ,doctor as doctor , " +
                "country as country ,province as province, cities as cities ,archiving as archiving ,remarks as remarks ,start_time as startTime ,end_time as endTime,left(create_appointment_time,19) as createAppointmentTime," +
                "customer_phone as customerPhone ," +
                "( " +
                " CASE customer_sex " +
                " WHEN 1 THEN " +
                " '男' " +
                " WHEN 2 THEN " +
                " '女' " +
                " ELSE " +
                " '未知' " +
                " END " +
                " ) as sex from " + ShiroKit.getUser().getCustomer_info() + " where id='" + customerId + "' order by arrival_time desc limit 0,1 ";
        CustomerInfo customerInfo = sqlMapper.selectOne(sql, CustomerInfo.class);
        model.addAttribute("customerInfo", customerInfo);
        model.addAttribute("customerId", customerId);
        return PREFIX + "printingAppointment.html";
    }

    /**
     * 跳转到发送短信
     */
    @RequestMapping("/shortMessage/{customerId}")
    public String shortMessage(@PathVariable String customerId, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        model.addAttribute("customerId", customerId);
        return PREFIX + "shortMessage.html";
    }

    /**
     * 得到医生收费明细
     */
    @RequestMapping("/getChargeSchedule")
    @ResponseBody
    public Object getChargeSchedule(SearchDoctorLookedInfo info, HttpServletRequest request) {
        Page<DoctorLookedInfo> page = new PageFactory<DoctorLookedInfo>().defaultPage();
        try {
            List<DoctorLookedInfo> list = service.selectChargeSchedule(page, info);
            page.setRecords(list);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return super.packForBT(page);
    }

    /**
     * 导出数据
     *
     * @return
     */
    @RequestMapping(value = "/chargeScheduleExport")
    public void chargeScheduleExport(
            @RequestParam(required = false) String startTime,
            @RequestParam(required = false) String endTime,
            @RequestParam(required = false) String payServiceName, HttpServletResponse response) {
        try {
            SearchDoctorLookedInfo info = new SearchDoctorLookedInfo();
            info.setStartTime(startTime);
            info.setEndTime(endTime);
            info.setPayServiceName(payServiceName);
            List<DoctorLookedInfo> list = service.chargeScheduleExportt(info);
            // 解析成excel文件
            // 第一步,创建一个webbook,对应一个Excel文件
            HSSFWorkbook wb = new HSSFWorkbook();
            // 第二步,在wb中添加一个sheet,对应Excel文件中的sheet
            HSSFSheet sheet = wb.createSheet("前端导出");
            for (int i = 0; i < 5; i++) {
                sheet.setColumnWidth(i, 24 * 256);
            }
            // 第三步,在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制short
            HSSFRow row = sheet.createRow(0);
            // 第四步,创建单元格,并设置值表头 设置表头居中
            HSSFCellStyle style = wb.createCellStyle();
            style.setAlignment(HorizontalAlignment.CENTER);// 创建一个居中格式
            HSSFCell cell = row.createCell(0);
            cell.setCellValue("医生");
            cell.setCellStyle(style);
            cell = row.createCell(1);
            cell.setCellValue("项目名称");
            cell.setCellStyle(style);
            cell = row.createCell(2);
            cell.setCellValue("数量");
            cell.setCellStyle(style);
            cell = row.createCell(3);
            cell.setCellValue("折后价");
            cell.setCellStyle(style);
            cell = row.createCell(4);
            cell.setCellValue("实收金额");
            cell.setCellStyle(style);
            // 填充数据
            for (int i = 0; i < list.size(); i++) {
                DoctorLookedInfo map = list.get(i);
                row = sheet.createRow(i + 1);
                String doctor = map.getDoctor();
                payServiceName = map.getPayServiceName();
                String payServiceNum = map.getPayServiceNum();
                String serviceActualPay = map.getServiceActualPay();
                String foldingPay = map.getFoldingPay();
                String customerName = map.getCustomerName();
                String customerPhone = map.getCustomerPhone();
                String sex = "";
                int customerSex = 0;
                if (map.getCustomerSex() != null) {
                    if (map.getCustomerSex() == 1) {
                        sex = "男";
                    } else if (map.getCustomerSex() == 2) {
                        sex = "女";
                    } else {
                        sex = "未知";
                    }
                }
                int customerAge = 0;
                if (map.getCustomerAge() != null) {
                    customerAge = map.getCustomerAge();
                }
                // 第四步,创建单元格,并设置值
                for (int j = 0; j <= 5; j++) {
                    row.createCell(j).setCellStyle(style);
                }
                row.getCell(0).setCellValue(doctor);
                row.getCell(1).setCellValue(payServiceName);
                row.getCell(2).setCellValue(payServiceNum);
                row.getCell(3).setCellValue(foldingPay);
                row.getCell(4).setCellValue(serviceActualPay);
            }
            String date = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new java.util.Date());
            String filename = "data" + date + ".xls";
            response.setHeader("Content-Disposition",
                    "attachment; filename=\"" + URLEncoder.encode(filename, "UTF-8") + "\"");
            response.setContentType("application/octet-stream;charset=UTF-8");
            OutputStream outputStream = new BufferedOutputStream(response.getOutputStream());
            wb.write(outputStream);
            outputStream.flush();
            outputStream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 医生划价预览导出数据
     *
     * @return
     */
    @RequestMapping(value = "/doctorChargeExport")
    public void doctorChargeExport(
            @RequestParam(required = false) String startTime,
            @RequestParam(required = false) String endTime,
            @RequestParam(required = false) Integer checkStatus,
            @RequestParam(required = false) String doctor,
            HttpServletResponse response) {
        try {
            SearchDoctorLookedInfo info = new SearchDoctorLookedInfo();
            info.setStartTime(startTime);
            info.setEndTime(endTime);
            info.setCheckStatus(checkStatus);
            info.setDoctor(doctor);
            List<DoctorLookedInfo> list = service.doctorChargePriceExport(info);
            // 解析成excel文件
            // 第一步,创建一个webbook,对应一个Excel文件
            HSSFWorkbook wb = new HSSFWorkbook();
            // 第二步,在wb中添加一个sheet,对应Excel文件中的sheet
            HSSFSheet sheet = wb.createSheet("前端导出");
//            if("1".equals(pageType)){
            for (int i = 0; i < 6; i++) {
                sheet.setColumnWidth(i, 24 * 256);
            }
            // 第三步,在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制short
            HSSFRow row = sheet.createRow(0);
            // 第四步,创建单元格,并设置值表头 设置表头居中
            HSSFCellStyle style = wb.createCellStyle();
            style.setAlignment(HorizontalAlignment.CENTER);// 创建一个居中格式
            HSSFCell cell = row.createCell(0);
            cell.setCellValue("患者姓名");
            cell.setCellStyle(style);
            cell = row.createCell(1);
            cell.setCellValue("电话");
            cell.setCellStyle(style);
            cell = row.createCell(2);
            cell.setCellValue("性别");
            cell.setCellStyle(style);
            cell = row.createCell(3);
            cell.setCellValue("医生");
            cell.setCellStyle(style);
            cell = row.createCell(4);
            cell.setCellValue("项目名称");
            cell.setCellStyle(style);
            cell = row.createCell(5);
            cell.setCellValue("划价状态");
            cell.setCellStyle(style);
            // 填充数据
            for (int i = 0; i < list.size(); i++) {
                DoctorLookedInfo map = list.get(i);
                row = sheet.createRow(i + 1);
                String payServiceName = map.getPayServiceName();
                String customerName = map.getCustomerName();
                String customerPhone = map.getCustomerPhone();
                doctor = map.getDoctor();
                String sex = "";
                int customerSex = 0;
                if (map.getCustomerSex() != null) {
                    if (map.getCustomerSex() == 1) {
                        sex = "男";
                    } else if (map.getCustomerSex() == 2) {
                        sex = "女";
                    } else {
                        sex = "未知";
                    }
                }
                String s = "";
                //int checkStatus =0;
                if (map.getCheckStatus() != null) {
                    if (map.getCheckStatus() == 1) {
                        s = "已划价";
                    } else if (map.getCheckStatus() == 2) {
                        s = "未划价";
                    }
                }
                int customerAge = 0;
                if (map.getCustomerAge() != null) {
                    customerAge = map.getCustomerAge();
                }
                // 第四步,创建单元格,并设置值
                for (int j = 0; j <= 5; j++) {
                    row.createCell(j).setCellStyle(style);
                }
                row.getCell(0).setCellValue(customerName);
                row.getCell(1).setCellValue(customerPhone);
                row.getCell(2).setCellValue(sex);
                row.getCell(3).setCellValue(doctor);
                row.getCell(4).setCellValue(payServiceName);
                row.getCell(5).setCellValue(s);
            }
            String date = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new java.util.Date());
            String filename = "data" + date + ".xls";
            response.setHeader("Content-Disposition",
                    "attachment; filename=\"" + URLEncoder.encode(filename, "UTF-8") + "\"");
            response.setContentType("application/octet-stream;charset=UTF-8");
            OutputStream outputStream = new BufferedOutputStream(response.getOutputStream());
            wb.write(outputStream);
            outputStream.flush();
            outputStream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //查询病历
    @RequestMapping(value = "/getCaseData", method = RequestMethod.POST)
    @ResponseBody
    public List<CaseInfo> getArchivings(String id) throws Exception {
        String sql = "select * from  case_info t1 LEFT JOIN tooth_site t2 on t1.id=t2.case_id where t1.id='" + id + "'";
        List<CaseInfo> list = sqlMapper.selectList(sql, CaseInfo.class);
        return list;
    }

    //删除随访模板
    @RequestMapping(value = "/deleteSfById", method = RequestMethod.POST)
    @ResponseBody
    public int deleteSfById(String id) throws Exception {
        String sql = "delete from follow_template where id='" + id + "'";
        return sqlMapper.delete(sql);
    }

    //删除矫治原则模板
    @RequestMapping(value = "/deleteJzById", method = RequestMethod.POST)
    @ResponseBody
    public int deleteJzById(String id) throws Exception {
        String sql = "delete from orthodontic_template where id='" + id + "'";
        return sqlMapper.delete(sql);
    }

    //删除设计方案模板
    @RequestMapping(value = "/deleteSjById", method = RequestMethod.POST)
    @ResponseBody
    public int deleteSjById(String id) throws Exception {
        String sql = "delete from design_scheme where id='" + id + "'";
        return sqlMapper.delete(sql);
    }

    //删除随访结果模板
    @RequestMapping(value = "/deleteJgById", method = RequestMethod.POST)
    @ResponseBody
    public int deleteJgById(String id) throws Exception {
        String sql = "delete from follow_results_template where id='" + id + "'";
        return sqlMapper.delete(sql);
    }

    //修改预约备注
    @RequestMapping(value = "/updRemarksReservation/{customerId}")
    public String updRemarksReservation(@PathVariable String customerId, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        String sql = "select id,remarks_reservation from " + ShiroKit.getUser().getCustomer_info() + " t" +
                " where t.id='" + customerId + "' limit 1";
        CustomerInfo customerInfo = sqlMapper.selectOne(sql, CustomerInfo.class);
        model.addAttribute("customerInfo", customerInfo);
        return PREFIX + "doctor_updRemarksReservation.html";
    }

    //修改预约备注
    @RequestMapping(value = "/updateRemarksReservationOk", method = RequestMethod.POST)
    @ResponseBody
    public int updateRemarksReservationOk(String customerId, String remarksReservation) throws Exception {
        String selsql = "select id, (case a.arrival_status when (1 or 9) then '预约' when 2 then '到店' when 3 then '就诊中' " +
                "when 4 then '完成治疗' when 5 then '离开' when (6 or 10) then '已打电话' " +
                "when 7 then '失约' when 8 then '取消预约' else '其他' end) as arrivalStatusName,a.customer_name,a.customer_phone,a.customer_status," +
                "a.reservations_id ,a.remarks_reservation from " + ShiroKit.getUser().getCustomer_info() + " a where id = '" + customerId + "' limit 1";
        CustomerInfo customerInfo = sqlMapper.selectOne(selsql, CustomerInfo.class);
        String sql = "update " + ShiroKit.getUser().getCustomer_info() + " set remarks_reservation='" + remarksReservation + "'" +
                " where id='" + customerId + "'";
        String sq11 = "INSERT INTO `customer_reservations_update_log` (createtime,single_person,logtype, `userid`, `customer_status`, `customer_name`,`customer_phone`," +
                " `succeed`,outpatient_name ,`message`,customer_id,reservations_id) VALUES " +
                " ('" + DateTimeKit.now() + "','" + ShiroKit.getUser().getAccount() + "','修改预约备注','" + ShiroKit.getUser().getId() + "','" + customerInfo.getCustomerStatus() + "', '"
                + customerInfo.getCustomerName() + "', '" + customerInfo.getCustomerPhone() + "','成功','" + ShiroKit.getUser().getOutpatientName() +
                "','修改预约备注：" + customerInfo.getRemarksReservation() + "->" + remarksReservation + "','" + customerId + "','" + customerInfo.getReservationsId() + "');";
        sqlMapper.update(sql);
        return sqlMapper.insert(sq11);
    }

    //修改看诊项目
    @RequestMapping(value = "/updAppointmentPayService/{customerId}")
    public String updAppointmentPayService(@PathVariable String customerId, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        String sql = "select id,appointment_pay_service from " + ShiroKit.getUser().getCustomer_info() + " t" +
                " where t.id='" + customerId + "' limit 1";
        ConsultantInfo consultantInfo = sqlMapper.selectOne(sql, ConsultantInfo.class);
        if (StringUtil.isNotEmpty(consultantInfo.getAppointmentPayService())) {
            String payService = consultantInfo.getAppointmentPayService().substring(0, consultantInfo.getAppointmentPayService().length() - 1);
            model.addAttribute("payService", payService);
        } else {
            model.addAttribute("payService", "");
        }
        model.addAttribute("customerId", customerId);
        return PREFIX + "doctor_updAppointmentPayService.html";
    }

    //修改看诊项目
    @RequestMapping(value = "/updAppointmentPayServiceOK", method = RequestMethod.POST)
    @ResponseBody
    public int updAppointmentPayServiceOK(String customerId, String projectData) throws Exception {
        String selsql = "select id, (case a.arrival_status when (1 or 9) then '预约' when 2 then '到店' when 3 then '就诊中' " +
                "when 4 then '完成治疗' when 5 then '离开' when (6 or 10) then '已打电话' " +
                "when 7 then '失约' when 8 then '取消预约' else '其他' end) as arrivalStatusName,a.customer_name,a.customer_phone,a.customer_status," +
                "a.reservations_id ,a.appointment_pay_service from " + ShiroKit.getUser().getCustomer_info() + " a where id = '" + customerId + "' limit 1";
        CustomerInfo customerInfo = sqlMapper.selectOne(selsql, CustomerInfo.class);
        String sql = "update " + ShiroKit.getUser().getCustomer_info() + " set appointment_pay_service='" + projectData + "'" +
                " where id='" + customerId + "'";
        String sq11 = "INSERT INTO `customer_reservations_update_log` (createtime,single_person,logtype, `userid`, `customer_status`, `customer_name`,`customer_phone`," +
                " `succeed`,outpatient_name ,`message`,customer_id,reservations_id) VALUES " +
                " ('" + DateTimeKit.now() + "','" + ShiroKit.getUser().getAccount() + "','修改看诊项目','" + ShiroKit.getUser().getId() + "','" + customerInfo.getCustomerStatus() + "', '"
                + customerInfo.getCustomerName() + "', '" + customerInfo.getCustomerPhone() + "','成功','" + ShiroKit.getUser().getOutpatientName() +
                "','修改看诊项目：" + customerInfo.getAppointmentPayService() + "->" + projectData + "','" + customerId + "','" + customerInfo.getReservationsId() + "');";
        sqlMapper.update(sql);
        return sqlMapper.insert(sq11);
    }

    //查看改动日志
    @RequestMapping(value = "/getUpdateLog/{customerId}")
    public String getUpdateLog(@PathVariable String customerId, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        model.addAttribute("customerId", customerId);
        return PREFIX + "doctor_getUpdateLog.html";
    }

    //查看随访改动日志
    @RequestMapping(value = "/doctor_daily/{reservationsId}")
    public String doctorDailyLog(@PathVariable String reservationsId, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        model.addAttribute("reservationsId", reservationsId);
        return PREFIX + "doctor_daily_log.html";
    }

    //查看病历操作日志
    @RequestMapping(value = "/caseLog/{id}")
    public String caseLog(@PathVariable String id, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        model.addAttribute("id", id);
        return PREFIX + "case_log.html";
    }

    //查看病历操作日志
    @RequestMapping(value = "/caseLogs/{reservationsId}")
    public String caseLogs(@PathVariable String reservationsId, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        model.addAttribute("reservationsId", reservationsId);
        return PREFIX + "case_logs.html";
    }

    //查看改动日志
    @RequestMapping("/getUpdateLogList/{customerId}")
    @ResponseBody
    public Object getUpdateLogList(@PathVariable String customerId, SearchCustomerReservationsUpdateLogInfo info, HttpServletRequest request) {
        Page<CustomerReservationsUpdateLogInfo> page = new PageFactory<CustomerReservationsUpdateLogInfo>().defaultPage();
        try {
            String sql = "select * from " + ShiroKit.getUser().getCustomer_info() + " where id='" + customerId + "' limit 1";
            CustomerInfo cinfo = sqlMapper.selectOne(sql, CustomerInfo.class);
            if (cinfo != null) {
                info.setCustomerId(customerId);
                info.setCustomerName(cinfo.getCustomerName());
                info.setCustomerPhone(cinfo.getCustomerPhone());
            }
            info.setStartIndex(page.getSize() * (page.getCurrent() - 1));
            info.setLimitIndex(page.getSize());
            page.setCurrent(0);
            List<CustomerReservationsUpdateLogInfo> list = statusLogService.getList(page, info);
            if (list.size() == 0) {
                info.setStartIndex(0);
                list = statusLogService.getList(page, info);
            }
            page.setRecords(list);
            page.setTotal(statusLogService.getQueryPagesCount(page, info));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return super.packForBT(page);
    }

    //查看 随访 改动日志
    @RequestMapping("/getDoctorDailyLogList/{reservationsId}")
    @ResponseBody
    public Object getDoctorDailyLogList(@PathVariable String reservationsId, SearchDoctorDailyLog info, HttpServletRequest request) {
        Page<DoctorDailyLog> page = new PageFactory<DoctorDailyLog>().defaultPage();
        try {
            String sql = "select * from " + ShiroKit.getUser().getCustomer_info() + " where reservations_id='" + reservationsId + "' limit 1";
            CustomerInfo cinfo = sqlMapper.selectOne(sql, CustomerInfo.class);
            if (cinfo != null) {
                info.setReservationsId(reservationsId);
            }
            info.setStartIndex(page.getSize() * (page.getCurrent() - 1));
            info.setLimitIndex(page.getSize());
            page.setCurrent(0);
            List<DoctorDailyLog> list = statusLogService.getDocotrDailyLogList(page, info);
            if (list.size() == 0) {
                info.setStartIndex(0);
                list = statusLogService.getDocotrDailyLogList(page, info);
            }
            page.setRecords(list);
            page.setTotal(statusLogService.getDailyPageCount(page, info));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return super.packForBT(page);
    }

    /**
     * 病历模板层级
     */
    @RequestMapping("/subsequent_membershipOther")
    public String subsequent_membershipOther(Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        return PREFIX + "subsequent_membershipOther.html";
    }

    /**
     * 修改黄页编号
     */
    @RequestMapping("/numberedModification/{yi}")
    public String numberedModification(@PathVariable String yi, Model model) {
        String yellowNumber = yi.split(",")[0];
        String customerId = yi.split(",")[1];

        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        model.addAttribute("customerId", customerId);
        model.addAttribute("yellowNumber", yellowNumber);
        return PREFIX + "doctor_numberedModification.html";
    }

    /**
     * 病历模板层级
     */
    @RequestMapping("/doctor_oblog")
    public String doctor_oblog(Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        return PREFIX + "doctor_oblog.html";
    }

    /**
     * 病历模板层级添加
     *
     * @param
     * @return
     */
    @RequestMapping(value = "/add_Oblogs", method = RequestMethod.POST)
    @ResponseBody
    public int add_Oblogs(String oneClass, String twoClass) {
        String sq11 = "INSERT INTO ob_log (one_class,two_class,doctor) VALUES " +
                " ('" + oneClass + "','" + twoClass + "','" + ShiroKit.getUser().getAccount() + "');";
        return sqlMapper.insert(sq11);
    }

    /**
     * 病历模板
     */
    @RequestMapping("/doctor_template/{val}")
    public String doctor_template(@PathVariable String val, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        String roleSql = "select a.name from role a left join user b on a.id=b.roleid where b.account='" + ShiroKit.getUser().getAccount() + "' limit 1";
        Role role = sqlMapper.selectOne(roleSql, Role.class);
        String caseInfoSql = "select distinct one_class as oneClass from ob_log where doctor='" + ShiroKit.getUser().getAccount() + "' ";
        if ("超级管理员".equals(role.getName())) {
            caseInfoSql = "select distinct one_class as oneClass from ob_log ";
        }
        List<CaseInfo> casesContent = sqlMapper.selectList(caseInfoSql, CaseInfo.class);
        Map<String, Object> reMap = new HashMap<String, Object>();
        for (CaseInfo caseInfo : casesContent) {
            //然后查询牙位集合
            String Sql2 = "select  id,two_class as twoClass from ob_log where one_class='" + caseInfo.getOneClass() + "' and doctor='" + ShiroKit.getUser().getAccount() + "'";
            List<CaseInfo> ci2 = sqlMapper.selectList(Sql2, CaseInfo.class);
            Map<String, Object> map = new HashMap<String, Object>();
            for (CaseInfo ci : ci2) {
                String Sql3 = "select * from cases_content a where oblogid='" + ci.getId() + "' and doctor='" + ShiroKit.getUser().getAccount() + "'";
                if ("超级管理员".equals(role.getName())) {
                    Sql3 = "select * from cases_content a where oblogid='" + ci.getId() + "' ";
                }
                List<CaseInfo> ci3 = sqlMapper.selectList(Sql3, CaseInfo.class);
                List<CaseInfo> list = new ArrayList<CaseInfo>();
                for (CaseInfo ci33 : ci3) {
                    if (ci.getId().equals(ci33.getOblogid())) {
                        //将循环的值添加到LIST中去
                        list.add(ci33);
                    }
                }
                //将LIST 添加到map
                map.put(ci.getTwoClass(), list);
            }
            reMap.put(caseInfo.getOneClass(), map);
        }
        model.addAttribute("val", val);
        model.addAttribute("reMap", reMap);
        return PREFIX + "doctor_template.html";
    }

    /**
     * 另存为病历模板
     */
    @RequestMapping("/doctor_saveTemplate")
    public String doctor_saveTemplate(Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        return PREFIX + "doctor_saveTemplate.html";
    }

    /**
     * 选择模板类别
     */
    @RequestMapping("/doctor_choiceTemplate")
    public String doctor_choiceTemplate(Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        String roleSql = "select a.name from role a left join user b on a.id=b.roleid where b.account='" + ShiroKit.getUser().getAccount() + "' limit 1";
        Role role = sqlMapper.selectOne(roleSql, Role.class);
        String caseInfoSql = "select distinct one_class as oneClass from ob_log where doctor='" + ShiroKit.getUser().getAccount() + "' ";
        if ("超级管理员".equals(role.getName())) {
            caseInfoSql = "select distinct one_class as oneClass from ob_log ";
        }
        List<CaseInfo> obloginfo = sqlMapper.selectList(caseInfoSql, CaseInfo.class);
        for (CaseInfo caseInfo : obloginfo) {
            //然后查询牙位集合
            String Sql2 = "select  id,two_class as twoClass from ob_log where one_class='" + caseInfo.getOneClass() + "' and  doctor='" + ShiroKit.getUser().getAccount() + "'";
            if ("超级管理员".equals(role.getName())) {
                Sql2 = "select  id,two_class as twoClass from ob_log where one_class='" + caseInfo.getOneClass() + "'";
            }
            List<CaseInfo> ci2 = sqlMapper.selectList(Sql2, CaseInfo.class);
            for (CaseInfo ci : ci2) {
                caseInfo.getCi().add(ci);
            }
        }
        model.addAttribute("obloginfo", obloginfo);
        return PREFIX + "doctor_choiceTemplate.html";
    }

    /**
     * 病历模板另存为
     *
     * @param
     * @return
     */
    @RequestMapping(value = "/addCaseContent", method = RequestMethod.POST)
    @ResponseBody
    public int addCaseContent(String caseName, String zhushu, String nowMedicalHistory, String beforeMedicalHistory
            , String mouthCheck, String auxiliaryCheck, String remedyPlan, String diagnose
            , String dispose, String doctorAdvice, String oblogid) {
        String sq11 = "INSERT INTO cases_content (oblogid,case_name, zhushu,now_medical_history,before_medical_history,mouth_check, " +
                "auxiliary_check,diagnose,remedy_plan,dispose,doctor_advice,doctor) VALUES " +
                " ('" + oblogid + "','" + caseName + "','" + zhushu + "', '" + nowMedicalHistory + "', '" + beforeMedicalHistory + "', '" + mouthCheck + "','" + auxiliaryCheck +
                "','" + diagnose + "','" + remedyPlan + "','" + dispose + "' ,'" + doctorAdvice + "','" + ShiroKit.getUser().getAccount() + "');";
        return sqlMapper.insert(sq11);
    }

    /**
     * 获取病历模板信息
     *
     * @param
     * @return
     */
    @RequestMapping(value = "/getCaseContent", method = RequestMethod.POST)
    @ResponseBody
    public CaseInfo getCaseContent(String id) {
        String sq11 = "select * from cases_content a left join ob_log b on a.oblogid=b.id " +
                "where a.id='" + id + "' limit 1";
        CaseInfo caseInfo = sqlMapper.selectOne(sq11, CaseInfo.class);
        return caseInfo;
    }

    /**
     * 删除模板
     *
     * @param
     * @return
     */
    @RequestMapping(value = "/deleteCaseContent", method = RequestMethod.POST)
    @ResponseBody
    public int deleteCaseContent(String id) {
        String role = "select a.name from role a left join user b on a.id=b.roleid where b.account='" + ShiroKit.getUser().getAccount() + "' limit 1";
        Role role1 = sqlMapper.selectOne(role, Role.class);
        String sq11;
        if ("超级管理员".equals(role1.getName())) {
            sq11 = "delete from cases_content  where id='" + id + "' ";
        } else {
            sq11 = "delete from cases_content   where id='" + id + "' and doctor='" + ShiroKit.getUser().getAccount() + "'";
        }
        return sqlMapper.delete(sq11);
    }

    /**
     * 修改保存黄页编号
     *
     * @param customerId
     * @return
     */
    @RequestMapping(value = "/updateNumber", method = RequestMethod.POST)
    @ResponseBody
    public int updateNumber(String customerId, String yellowNumber) {
        String sql1 = "select t.customer_name as customerName,t.customer_phone as customerPhone,t.yellow_number as yellowNumber,t.archiving as archiving,t.id," +
                "t.reservations_id as reservationsId from " + ShiroKit.getUser().getCustomer_info() + " t where id='" + customerId + "' limit 1";
        CustomerInfo info = sqlMapper.selectOne(sql1, CustomerInfo.class);
        String sql = "update " + ShiroKit.getUser().getCustomer_info() + "  set yellow_number ='" + yellowNumber + "'" +
                " where reservations_id = '" + info.getReservationsId() + "'";

        String sq11 = "INSERT INTO yellow_number_update_log (logtype, userid,customer_name,customer_phone,single_person, createtime,succeed,classname) VALUES " +
                " ( '修改'," + ShiroKit.getUser().getId() + ", '" + info.getCustomerName() + "', '" + info.getCustomerPhone() + "', '" + ShiroKit.getUser().getAccount() + "','" + DateTimeKit.now() + "'," +
                "'成功','" + ShiroKit.getUser().getAccount() + " 把 " + info.getCustomerName() + " 的黄页编号:" + info.getYellowNumber() + " 修改为:" + yellowNumber + "');";
        sqlMapper.insert(sq11);
        return sqlMapper.update(sql);
    }

    /**
     * 添加就诊记录
     *
     * @param info
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/add_record")
    @ResponseBody
    public int addRecord(@Valid DoctorRevisitInfo info, String customerId, String doctor, String diagnoseTime, String expenditureProject, String diagnoseDetail, String remarks) throws Exception {
        //改变详情表状态
        String sql = "update  return_doctor_visit_info  set revisit_status= '2'  where customer_id='" + customerId + "'";
        sqlMapper.update(sql);
        String sql1 = "select * from " + ShiroKit.getUser().getCustomer_info() + " where id= '" + customerId + "' limit 1";
        DoctorDiagnosisInfo info1 = sqlMapper.selectOne(sql1, DoctorDiagnosisInfo.class);
        String sql2 = "insert into  `doctor_diagnosis_info` (`customer_id`,`reservations_id`,`doctor`,`diagnose_detail`," +
                "`diagnose_time`,pay_service_name,remarks,outpatient_name) VALUES" +
                "('" + customerId + "','" + info1.getReservationsId() + "','" + doctor + "','" + diagnoseDetail
                + "','" + diagnoseTime + "','" + expenditureProject + "','" + remarks + "','" + info1.getArrivalStore()
                + "');";
        return sqlMapper.insert(sql2);
    }

    /**
     * 医生完成治疗回访
     */
    @RequestMapping("/alreadyLeave/{cri}")
    public String startTreatment(@PathVariable String cri, Model model) {
        String customerId = cri.split(",")[0];
        String reservationsId = cri.split(",")[1];
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        model.addAttribute("doctor", ShiroKit.getUser().getAccount());
        model.addAttribute("customerId", customerId);
        model.addAttribute("reservationsId", reservationsId);
        return PREFIX + "alreadyLeave.html";
    }

    /**
     * 点击客户 获取 患者信息 看诊记录 病例记录  成交记录  回访记录
     *
     * @param id
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/doctor_seeDiagnosis/{id}/{tabId}")
    public String doctor_seeDiagnosis(@PathVariable String id, @PathVariable int tabId, Model model) throws Exception {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        if (ToolUtil.isEmpty(id)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        CustomerInfo customerInfo1 = customerService.selectOneById(id);
        if (customerInfo1.getReservationsId() == null) {
            return "/doNoClose.html";
        }
        CustomerInfo customerInfo = customerService.selectOneByReservationsId(customerInfo1.getReservationsId());
        //看诊详情
        List<ConsultantInfo> consultantInfoList = consultantService.getConsultantInfoList(customerInfo.getReservationsId());
        String sqlresrvations = "select id,content from reservations_info where id='" + customerInfo.getReservationsId() + "' limit 0,1";
        ReservationsInfo reservationsInfo = sqlMapper.selectOne(sqlresrvations, ReservationsInfo.class);
        if (reservationsInfo == null) {
            reservationsService.insert(customerInfo);
            model.addAttribute("content", "");
        } else {
            model.addAttribute("content", reservationsInfo.getContent());
        }
        String tcName = "";
        String firstVisitDate = "";
        if (customerInfo != null) {
            tcName = customerInfo.getFieldTc();
            firstVisitDate = customerInfo.getFirstVisitDate();
        }
        for (ConsultantInfo info1 : consultantInfoList) {
            if (info1.getDiagnosisTime() != "" && info1.getDiagnosisTime() != null) {
                info1.setDiagnosisTimeOne(info1.getDiagnosisTime().substring(0, 10));
                info1.setDiagnosisTimeTwo(info1.getDiagnosisTime().substring(11, info1.getDiagnosisTime().length()));
            }
        }
        //成交记录
        String sql = "select t1.id as id,t1.customer_id as customerId ,t1.reservations_id as reservationsId ,t1.orthodontic_number as orthodonticNumber,t1.outpatient_name as outpatientName , t1.deal_status  as dealStatus, t1.tc_name as tcName ,t1.pay_service_num as payServiceNum ," +
                " t1.service_actual_pay as serviceActualPay ,left(t1.operation_time,19) as operationTime," +
                "sum(t1.service_actual_pay) as totleServiceActualPay,sum(t1.deduction_amount) as totalDeductionAmount," +
                "(select sum(folding_pay) from " + ShiroKit.getUser().getDeal_info() + " a where a.operation_time=t1.operation_time and a.operation_time=a.get_time) as totleFoldingPay," +
                "sum(t1.arrears) as totleArrears,group_concat(distinct t1.remarks) as remarks," +
                " t1.folding_pay as foldingPay,t1.pay_service as payService," +
                "t2.id as payServiceId,t2.department as department,t2.first_level_project as firstLevelProject,t1.arrears as arrears," +
                "group_concat(distinct t2.pay_service_name) as payServiceName, t2.pay_service_price_one as payServicePriceOne, t2.pay_service_price_two as payServicePriceTwo," +
                "left(t1.get_time,19) as getTime ," +
                " group_concat(distinct t1.doctor) as doctor" +
                " from " + ShiroKit.getUser().getDeal_info() + " t1 left join " + ShiroKit.getUser().getPay_service_info() + " t2 on t1.pay_service_id=t2.id " +
                " where t1.reservations_id='" + customerInfo.getReservationsId() + "' and pay_service_id is not null and t1.deal_status='已结账' group by  operationTime order by operationTime desc";
        List<PayServicedInfo> payServiceInfoList = sqlMapper.selectList(sql, PayServicedInfo.class);
        String getTime = "";
        for (PayServicedInfo info : payServiceInfoList) {
            if (info != null) {
                if (info.getOperationTime() != "" && info.getOperationTime() != null) {
                    info.setOperationTimeOne(info.getOperationTime().substring(0, 10));
                    info.setOperationTimeTwo(info.getOperationTime().substring(11, info.getOperationTime().length()));
                }
                getTime = info.getGetTime();
            }
            if (StringUtil.isNotEmpty(info.getOrthodonticNumber())) {
                customerInfo.setOrthodonticNumber(info.getOrthodonticNumber());
            }
        }
        //通过预约ID  执行记录
        String sqll = "select t1.id as id,t1.id2 as id2,t1.customer_id as customerId,t1.reservations_id as reservationsId ,t1.outpatient_name as outpatientName , t1.deal_status  as dealStatus,t1.pay_service_num as payServiceNum ," +
                " t1.service_actual_pay as serviceActualPay ,left(t1.operation_time,19) as operationTime,left(t3.recharge_time,19) as rechargeTime,t1.remarks as remarks," +
                " t1.arrears as arrears,t2.pay_service_name as payServiceName,t1.get_time as getTime from " + ShiroKit.getUser().getDeal_info() + " t1 left join " + ShiroKit.getUser().getPay_service_info() + " t2 on t1.pay_service_id=t2.id left join " + ShiroKit.getUser().getRecharge_info() + " t3 on t3.id2=t1.id2 " +
                " where t1.reservations_id='" + customerInfo.getReservationsId() + "' and  t1.deal_status ='已结账'  group by  operationTime order by operationTime desc";
        List<PayServicedInfo> payServiceInfoList1 = sqlMapper.selectList(sqll, PayServicedInfo.class);
        Double totleReceivable = 0.00;
        Double totleFoldingPay = 0.00;   //
        Double totleServiceActualPay = 0.00; //总实收
        Double accountArrears = 0.00;  //总欠款
        for (PayServicedInfo info : payServiceInfoList1) {
            if (info != null) {
                if (info.getPayServiceId() != null && info.getPayServiceId() != "") {
                    if (info.getFoldingPay() != null) {
                        totleFoldingPay += info.getFoldingPay();
                    }
                    //总实收
                    if (info.getServiceActualPay() != null) {
                        totleServiceActualPay += info.getServiceActualPay();
                    }
                    //总欠款
                    if (info.getArrears() != null) {
                        accountArrears += info.getArrears();
                    }
                    info.setTotleReceivable(totleReceivable);
                    info.setTotleFoldingPay(totleFoldingPay);
                    info.setTotleServiceActualPay(totleServiceActualPay);
                    info.setAccountArrears(accountArrears);
                }
                if (info.getOperationTime() != "" && info.getOperationTime() != null) {
                    info.setOperationTimeOne(info.getOperationTime().substring(0, 10));
                    info.setOperationTimeTwo(info.getOperationTime().substring(11, info.getOperationTime().length()));
                }
                if (info.getRechargeTime() != "" && info.getRechargeTime() != null) {
                    info.setRechargeTimeOne(info.getRechargeTime().substring(0, 10));
                    info.setRechargeTimeTwo(info.getRechargeTime().substring(11, info.getRechargeTime().length()));
                }
            }
        }
        //病例记录
        //1、先查询当前客户的所有病例记录
        String caseInfoSql = "select left(t1.finnally_time,19) as finnallyTime1,t1.* from case_info t1  where t1.reservations_id='" + customerInfo.getReservationsId() + "'order by t1.finnally_time desc";
        List<CaseInfo> caseInfoList = sqlMapper.selectList(caseInfoSql, CaseInfo.class);
        for (CaseInfo infos : caseInfoList) {
            if (infos != null) {
                if (infos.getOperationTime() != "" && infos.getOperationTime() != null) {
                    infos.setOperationTime(infos.getOperationTime().substring(0, 10));
                }
                String sql3 = "select pay_service_name as payServiceName from " + ShiroKit.getUser().getPay_service_info() + " where id ='" + infos.getPayServiceId() + "' limit 1";
                CaseInfo caseInfo1 = sqlMapper.selectOne(sql3, CaseInfo.class);
                if (caseInfo1 == null) {
                    continue;
                }
                infos.setPayServiceName(caseInfo1.getPayServiceName());
            }
        }
        //2.循环遍历每个病例记录,给对应病例的牙位属性赋值
        for (CaseInfo caseInfo : caseInfoList) {
            //然后查询牙位集合
            String toothSIteSql = "select * from tooth_site t1 where t1.case_id='" + caseInfo.getId() + "' ";
            List<ToothSite> toothSiteList = sqlMapper.selectList(toothSIteSql, ToothSite.class);
            for (ToothSite toothSite : toothSiteList) {
                //根据对应的牙位类型,给病例实体的对应牙位属性赋值
                if (toothSite.getYaType().equals("1")) {
                    caseInfo.getToothSite1List().add(toothSite);
                }
                if (toothSite.getYaType().equals("2")) {
                    caseInfo.getToothSite2List().add(toothSite);
                }
                if (toothSite.getYaType().equals("3")) {
                    caseInfo.getToothSite3List().add(toothSite);
                }
                if (toothSite.getYaType().equals("4")) {
                    caseInfo.getToothSite4List().add(toothSite);
                }
                if (toothSite.getYaType().equals("5")) {
                    caseInfo.getToothSite5List().add(toothSite);
                }
            }
        }
        //随访记录
        String sql4 = "select r.id,r.reservations_id,r.customer_id,r.revisit,r.revisit_time,r.outpatient_name,r.revisit_content,r.doctor,r.revisit_status," +
                "r.remarks  from return_doctor_visit_info r where r.reservations_id ='" + customerInfo.getReservationsId() + "' ";
        List<DoctorRevisitInfo> doctorRevisitInfo = sqlMapper.selectList(sql4, DoctorRevisitInfo.class);
        //到过的店
        String abbreviationSql = "select abbreviation from distinction_customer_status where reservations_id = '" + reservationsInfo.getId() + "' ";
        List<String> abbreviationList = sqlMapper.selectList(abbreviationSql, String.class);
        String dealTables = "";
        String rechargeTables = "";
        String customerTables = "";
        String customerTablesd = "";
        for (int i = 0; i < abbreviationList.size(); i++) {
            String head = abbreviationList.get(i);
            if (i == abbreviationList.size() - 1) {
                dealTables += "select * from " + head + "deal_info where reservations_id='" + reservationsInfo.getId() + "' ";
                rechargeTables += "select document_number,deal_id,id2,recharge_people,operation_time,remarks from " + head + "recharge_info where reservations_id='" + reservationsInfo.getId() + "' ";
                customerTables += "select customer_name as customerName, left(t.create_appointment_time,19) as createAppointmentTime,left(t.start_time,19) as startTime,t.id as id,t.remarks_reservation as remarksReservation," +
                        "t.reservations_id as reservationsId,t.doctor as doctor,t.field_tc as fieldTc,t.remarks as remarks,t.arrival_status as arrivalStatus," +
                        "t.archiving as archiving,t.arrival_store as arrivalStore,t.customer_status as customerStatus,t.status as status," +
                        "t.appointment_pay_service as appointmentPayService " +
                        "from " + head + "customer_info t where reservations_id='" + customerInfo.getReservationsId() + "' ";
                customerTablesd += "select id,appointment_pay_service,arrival_time,archiving,field_tc from " + head + "customer_info t where reservations_id='" + customerInfo1.getReservationsId() + "' and arrival_time is not null";
            } else {
                dealTables += "select * from " + head + "deal_info where reservations_id='" + reservationsInfo.getId() + "' union ";
                rechargeTables += "select document_number,deal_id,id2,recharge_people,operation_time,remarks from " + head + "recharge_info where reservations_id='" + reservationsInfo.getId() + "' union ";
                customerTables += "select customer_name as customerName, left(t.create_appointment_time,19) as createAppointmentTime,left(t.start_time,19) as startTime,t.id as id,t.remarks_reservation as remarksReservation," +
                        "t.reservations_id as reservationsId,t.doctor as doctor,t.field_tc as fieldTc,t.remarks as remarks,t.arrival_status as arrivalStatus," +
                        "t.archiving as archiving,t.arrival_store as arrivalStore,t.customer_status as customerStatus,t.status as status," +
                        "t.appointment_pay_service as appointmentPayService " +
                        "from " + head + "customer_info t where reservations_id='" + customerInfo.getReservationsId() + "' union ";
                customerTablesd += "select id,appointment_pay_service,arrival_time,archiving,field_tc " +
                        "from " + head + "customer_info t where reservations_id='" + customerInfo.getReservationsId() + "' " +
                        "and arrival_time is not null  union ";
            }
        }
        if (abbreviationList.size() == 0) {
            return "/doNoClose.html";
        }
        FirstCustomerInfo customerInfoFirst = customerService.selectOneByReservationsIdFirst(customerInfo1.getReservationsId(), customerTablesd);  //首次到店患者信息
        //就诊记录
        String sql11 = "select * from (" + customerTables + ") t order by t.startTime desc";
        List<CustomerInfo> customerInfoList = sqlMapper.selectList(sql11, CustomerInfo.class);
        for (CustomerInfo infos : customerInfoList) {
            infos.setOutpatientName(ShiroKit.getUser().getOutpatientName());
            if (infos.getStartTime() != "" && infos.getStartTime() != null) {
                infos.setStartTimeOne(infos.getStartTime().substring(0, 10));
                infos.setStartTimeTwo(infos.getStartTime().substring(11, infos.getStartTime().length()));
            }
        }
        //账单记录
        Double totalServiceActualPay = 0.00;
        Double totalArrears = 0.00;
        String custDealSql = "select t1.id2 as id2," +
                "t1.reservations_id as reservationsId, " +
                "t1.outpatient_name as outpatientName," +
                "left(t1.operation_time,19) as operationTime," +
                "t1.deal_status as dealStatus," +
                "GROUP_CONCAT( distinct (t1.doctor)) as doctor,GROUP_CONCAT( distinct (t1.nurse)) as nurse," +
                "t1.tc_name as tcName," +
                "sum(t1.service_actual_pay+t1.arrears+t1.deduction_amount+t1.deposit_amount) AS foldingPay," +
                "sum(t1.service_actual_pay) as serviceActualPay," +
                "sum(t1.arrears) as arrears," +
                "sum(t1.deduction_amount) as deductionAmount," +
                "sum(t1.deposit_amount) as depositAmount," +
                "t1.remarks as  remarks,(select distinct(r1.document_number) from (" + rechargeTables + ") r1 where r1.deal_id=t1.id group by r1.deal_id) as documentNumber " +
                "from (" + dealTables + ") t1 where t1.deal_status='已结账' and  t1.reservations_id = '" + customerInfo.getReservationsId() + "' " +
                "group by t1.operation_time order by t1.operation_time desc";
        List<PayServicedInfo> custDealList = sqlMapper.selectList(custDealSql, PayServicedInfo.class);
        for (int i = 0; i < custDealList.size(); i++) {
            List<PayServicedInfo> dealList = getDealInfoList(custDealList.get(i).getOperationTime(), custDealList.get(i).getReservationsId());
            custDealList.get(i).setDealList(dealList);
            custDealList.get(i).setDocumentNumber(dealList.get(0).getDocumentNumber());
            totalServiceActualPay = totalServiceActualPay + custDealList.get(i).getServiceActualPay() + custDealList.get(i).getDepositAmount();
            totalArrears = totalArrears + custDealList.get(i).getArrears();
        }
        //支付记录
        String payDealSql = "select t.outpatient_name as outpatientName,left(t.get_time,19) as getTime,t.is_do as isDo,t.tc_name as tcName,t.deal_status as dealStatus,t2.recharge_people " +
                "as rechargePeople,sum(t.folding_pay) as foldingPay,sum(t.service_actual_pay) as serviceActualPay, sum(t.arrears) as arrears," +
                "(sum(t.folding_pay)+sum(t.arrears)) as tkfoldingPay,sum(t.deduction_amount) AS deductionAmount,sum(t.deposit_amount) as depositAmount," +   //退款=应收+欠费
                "t2.remarks as remarks from (" + dealTables + ") t left join (select b.id2 as id2, b.recharge_people as recharge_people, " +
                "b.operation_time as operation_time,b.remarks as remarks from (" + rechargeTables + ") b group by b.operation_time) t2 on t.get_time = t2.operation_time  where " +
                "t.reservations_id='" + customerInfo.getReservationsId() + "' and t.deal_status = '已结账' group by t.get_time order by t.get_time desc;";
        List<PayServicedInfo> payDealList = sqlMapper.selectList(payDealSql, PayServicedInfo.class);
        Double totalPayDealActualPay = 0.00;
        Double totalPayDealArrears = 0.00;
        for (int i = 0; i < payDealList.size(); i++) {
            totalPayDealActualPay = BigDecimal.valueOf(totalPayDealActualPay).add(BigDecimal.valueOf(payDealList.get(i).getServiceActualPay())).doubleValue();
            totalPayDealActualPay = BigDecimal.valueOf(totalPayDealActualPay).add(BigDecimal.valueOf(payDealList.get(i).getDepositAmount())).doubleValue();

            totalPayDealArrears = BigDecimal.valueOf(totalPayDealArrears).add(BigDecimal.valueOf(payDealList.get(i).getArrears())).doubleValue();
        }
        //欠费记录
        String arrearsDealSql = "select * from (select t.id2 as id2,t.reservations_id as reservationsId,t.customer_id as customerId," +
                " t.deal_status as dealStatus,t.outpatient_name as outpatientName,t.remarks as remarks,left(t.operation_time,19) as operationTime," +
                " t.doctor as doctor,t.tc_name as tcName,t.nurse as nurse,sum(t.deposit_amount) AS depositAmount,sum(t.deduction_amount) AS deductionAmount,sum(t.folding_pay) as foldingPay," +
                " sum(t.service_actual_pay)+sum(t.deposit_amount) as serviceActualPay,sum(t.arrears) as arrears,group_concat(distinct t1.pay_service_name) as payServiceName " +
                " from (" + dealTables + ") t  left join " + ShiroKit.getUser().getPay_service_info() + " t1 on t.pay_service_id=t1.id where t.deal_status='已结账' group by t.operation_time ) t1 " +
                " where t1.reservationsId = '" + customerInfo.getReservationsId() + "' and t1.arrears  >0 order by t1.operationTime desc;";
        List<PayServicedInfo> arrearsDealList = sqlMapper.selectList(arrearsDealSql, PayServicedInfo.class);
        Double totalArrearsAmount = 0.00;
        for (int i = 0; i < arrearsDealList.size(); i++) {
            totalArrearsAmount += arrearsDealList.get(i).getArrears();
        }
        List<ConsultantInfo> consultantInfoList2 = consultantService.getConsultantInfoList2(customerInfo.getReservationsId());
        String selectsql = "select id from today_operation_info where reservations_id='" + customerInfo.getReservationsId() + "' and " +
                " left(operation_time,10)='" + DateTimeKit.now().substring(0, 10) + "' and operation_people='" + ShiroKit.getUser().getAccount() + "' " +
                " and store='" + customerInfo.getArrivalStore() + "'";
        List<DoctorOperationInfo> doctorOperationInfo = sqlMapper.selectList(selectsql, DoctorOperationInfo.class);
        if (doctorOperationInfo.size() == 0) { //是否操作过该患者
            //插入 今日操作数据 医生
            String insertSql = " INSERT INTO today_operation_info  (customer_id,reservations_id,szm,operation_people,customer_name, " +
                    " customer_sex,customer_age, customer_phone,store,operation_time) values  " +
                    " ('" + id + "','" + customerInfo.getReservationsId() + "','" + customerInfo.getSzm() + "','" + ShiroKit.getUser().getAccount() + "','" + customerInfo.getCustomerName() + "','" + customerInfo.getCustomerSex() + "', " +
                    " '" + customerInfo.getCustomerAge() + "','" + customerInfo.getCustomerPhone() + "','" + customerInfo.getArrivalStore() + "','" + DateTimeKit.now() + "') ";
            sqlMapper.insert(insertSql);
        } else { //修改 今日操作数据时间 医生
            String updatesql = "update today_operation_info set operation_time='" + DateTimeKit.now() + "' where reservations_id='" + customerInfo.getReservationsId() + "' and " +
                    " left(operation_time,10)='" + DateTimeKit.now().substring(0, 10) + "' and operation_people='" + ShiroKit.getUser().getAccount() + "' " +
                    " and store='" + customerInfo.getArrivalStore() + "'";
            sqlMapper.update(updatesql);
        }
        //获得患者的到店时间
        String sql1 = "select left(arrival_time,19) as arrivalTime from " + ShiroKit.getUser().getCustomer_info() + " " +
                "where arrival_status!=1 and arrival_status!=6 and arrival_status!=7 and arrival_status!=8 and arrival_status!=9 and arrival_status!=10 and reservations_id = '" + customerInfo.getReservationsId() + "' and arrival_time is not null order by arrival_time DESC ";
        List<CustomerInfo> customerList = sqlMapper.selectList(sql1, CustomerInfo.class);
        //获得影像信息
        String sqlIcon = "select  i.id ,i.customer_id as customerId,i.reservations_id as reservationsId,i.num as num ,i.add_time as addTime " +
                "from icon_infos i  where i.reservations_id='" + customerInfo.getReservationsId() + "' group by i.num order by num DESC";
        List<IconInfo> iconList = sqlMapper.selectList(sqlIcon, IconInfo.class);
        for (int i = 0; i < iconList.size(); i++) {
            List<IconInfo> currentList = getCurrentList(iconList.get(i).getNum(), iconList.get(i).getReservationsId());
            iconList.get(i).setCurrentList(currentList);
        }
        if (ShiroKit.getUser().getTcList() == null) {
            String getListSql = " select a.id as id,a.account as tcName from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on a.roleid=c.id " +
                    " where b.abbreviation='"+tableHead+"' and c.name like CONCAT('%','tc','%') ";
            List<TcInfo> tcList =sqlMapper.selectList(getListSql,TcInfo.class);
            ShiroKit.getUser().setTcList(tcList);
        }
        if (ShiroKit.getUser().getDoctorInfoList() == null) {
            String doctorListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + ShiroKit.getUser().getAbbreviation() + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            List<DoctorInfo> doctorInfoList=sqlMapper.selectList(doctorListSql,DoctorInfo.class);
            ShiroKit.getUser().setDoctorInfoList(doctorInfoList);
        }
        model.addAttribute("doctorList", ShiroKit.getUser().getDoctorInfoList());
        if (ShiroKit.getSessionAttr("consumablesList") == null) {
            String getListSql = "select id,name as name,add_time as addTime,num as num from consumable_info ";
            List<ConsumablesNameInfo> listInfo = sqlMapper.selectList(getListSql, ConsumablesNameInfo.class);
            ShiroKit.setSessionAttr("consumablesList", listInfo);
        }
        if (ShiroKit.getSessionAttr("processUnitInfoList") == null) {
            String selectSql = "select id,add_name as addName,process_unit as processUnit,create_time as createTime from processing_unit ";
            List<ProcessUnitInfo> processUnitInfoList = sqlMapper.selectList(selectSql, ProcessUnitInfo.class);
            ShiroKit.setSessionAttr("processUnitInfoList", processUnitInfoList);
        }
        if (ShiroKit.getSessionAttr("pickerInfoList") == null) {
            String selectSql = "select id,add_name as addName,picker as picker,create_time as createTime from picker ";
            List<PickerInfo> pickerInfoList = sqlMapper.selectList(selectSql, PickerInfo.class);
            ShiroKit.setSessionAttr("pickerInfoList", pickerInfoList);
        }
        model.addAttribute("pickerInfoList", ShiroKit.getSessionAttr("pickerInfoList"));
        model.addAttribute("processUnitInfoList", ShiroKit.getSessionAttr("processUnitInfoList"));
        model.addAttribute("consumablesList", ShiroKit.getSessionAttr("consumablesList"));
        model.addAttribute("tcList", ShiroKit.getUser().getTcList());
        model.addAttribute("outpatientManagementList", ShiroKit.getSessionAttr("outpatientManagementList"));
        model.addAttribute("iconList", iconList);
        model.addAttribute("customerList", customerList);
        model.addAttribute("custDealList", custDealList);
        model.addAttribute("payDealList", payDealList);
        model.addAttribute("consultantInfoList2", consultantInfoList2);
        model.addAttribute("arrearsDealList", arrearsDealList);
        model.addAttribute("totalServiceActualPay", totalServiceActualPay);
        model.addAttribute("totalArrears", totalArrears);
        model.addAttribute("totalPayDealActualPay", totalPayDealActualPay);
        model.addAttribute("totalPayDealArrears", totalPayDealArrears);
        model.addAttribute("totalArrearsAmount", totalArrearsAmount);
        model.addAttribute("userName", ShiroKit.getUser().getAccount());
        model.addAttribute("roleNameLogin", ShiroKit.getUser().getRoleName());
        model.addAttribute("dealyesLogin", ShiroKit.getUser().getDealyes());
        model.addAttribute("storeValue", ShiroKit.getUser().getOutpatientName());
        model.addAttribute("doctorValue", ShiroKit.getUser().getAccount());
        model.addAttribute("reservationsId", customerInfo.getReservationsId());
        model.addAttribute("customerId", id);
        model.addAttribute("customerInfo", customerInfo);
        model.addAttribute("medicalRecordNumber", customerInfo.getMedicalRecordNumber());
        model.addAttribute("customerInfoFirst", customerInfoFirst);  //首次到店患者信息
        model.addAttribute("payServiceInfoList", payServiceInfoList);
        model.addAttribute("payServiceInfoList1", payServiceInfoList1);
        model.addAttribute("getTime", getTime);
        model.addAttribute("tabId", tabId);
        model.addAttribute("tcName", tcName);
        model.addAttribute("firstVisitDate", firstVisitDate);
        model.addAttribute("consultantInfo", customerInfo);
        model.addAttribute("consultantInfoList", consultantInfoList);
        model.addAttribute("caseInfoList", caseInfoList);
        model.addAttribute("doctorRevisitInfo", doctorRevisitInfo);
        model.addAttribute("doctorDiagnosisInfo", customerInfoList);
        String jfbalancesql = "select if(sum(score_balance) is null,0,sum(score_balance)) as scoreBalance from return_cash_info where reservations_id='" + customerInfo.getReservationsId() + "'";
        ScoreDealInfo scoreDealInfo = sqlMapper.selectOne(jfbalancesql, ScoreDealInfo.class);
        Double moneyBalance = customerInfo.getMoneyBalance();
        model.addAttribute("jfbalance", scoreDealInfo.getScoreBalance());
        model.addAttribute("khjfbalance", scoreDealInfo.getScoreBalance());
        String getMoneyBalance = "select if(sum(a.actual_account_balance) is null,0,sum(a.actual_account_balance)) as moneyBalance from reservemoney_deal a " +
                " where a.reservations_id='" + customerInfo1.getReservationsId() + "' limit 1";
        MembersUser membersUser1 = sqlMapper.selectOne(getMoneyBalance, MembersUser.class);
        model.addAttribute("moneyBalance", membersUser1.getMoneyBalance());
        model.addAttribute("khmoneyBalance", membersUser1.getMoneyBalance());
        model.addAttribute("isRefundAdmin", ShiroKit.getUser().getIsRefundAdmin());
        if (tabId == 0) {
            return PREFIX + "doctor_seeDiagnosis.html";
        } else if (tabId == 1) {
            return PREFIX + "doctor_seeDiagnosis1.html";
        } else if (tabId == 2) {
            return PREFIX + "doctor_seeDiagnosis2.html";
        } else if (tabId == 3) {
            return PREFIX + "doctor_seeDiagnosis3.html";
        } else if (tabId == 4) {
            return PREFIX + "doctor_seeDiagnosis4.html";
        } else if (tabId == 5) {
            return PREFIX + "doctor_seeDiagnosis5.html";
        } else if (tabId == 6) {
            return PREFIX + "doctor_seeDiagnosis6.html";
        } else if (tabId == 7) {
            return PREFIX + "doctor_seeDiagnosis7.html";
        } else if (tabId == 8) {
            return PREFIX + "doctor_seeDiagnosis8.html";
        } else {
            return PREFIX + "doctor_seeDiagnosis.html";
        }
    }

    public List<PayServicedInfo> getDealInfoList(String operationTime, String reservationsId) throws Exception {
        if (ToolUtil.isEmpty(operationTime)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String abbreviationSql = "select abbreviation from distinction_customer_status where reservations_id = '" + reservationsId + "' and status=1 ";
        List<String> abbreviationList = sqlMapper.selectList(abbreviationSql, String.class);
        String dealTables = "";
        String rechargeTables = "";
        for (int i = 0; i < abbreviationList.size(); i++) {
            String head = abbreviationList.get(i);
            if (i == abbreviationList.size() - 1) {
                dealTables += "select * from " + head + "deal_info where reservations_id='" + reservationsId + "' ";
                rechargeTables += "select * from " + head + "recharge_info where reservations_id='" + reservationsId + "' ";
            } else {
                dealTables += "select * from " + head + "deal_info where reservations_id='" + reservationsId + "' union ";
                rechargeTables += "select * from " + head + "recharge_info where reservations_id='" + reservationsId + "' union ";
            }
        }
        String sql = "select t1.id as id,t1.outpatient_name as outpatientName,left(t1.get_time,19) as getTime,t1.is_do as isDo,t1.deal_status as dealStatus," +
                "t1.doctor1 as doctor,t1.nurse1 as nurse,t1.order_discount as orderDiscount,t1.deductionAmount as deductionAmount,t1.remarks as remarks,t1.serviceActualPay as serviceActualPay," +
                "t2.recharge_people as rechargePeople,t2.checkout_method as checkoutMethod," +
                "t2.document_number as documentNumber,t1.tc_name as tcName,left(t1.operation_time,19) as operationTime from (select t.id2 as id,t.outpatient_name as outpatient_name," +
                "t.get_time as get_time,t.tc_name as tc_name,t.is_do as is_do,t.deal_status as deal_status,GROUP_CONCAT(DISTINCT t.doctor) AS doctor1,GROUP_CONCAT(DISTINCT t.nurse) AS nurse1,(sum(t.service_actual_pay)+sum(t.deposit_amount)) as serviceActualPay," +
                "t.order_discount as order_discount,sum(t.deduction_amount) as deductionAmount,t.remarks as remarks,t.operation_time as operation_time from (" + dealTables + ") t where t.operation_time='" + operationTime + "' and t.reservations_id " +
                "= '" + reservationsId + "' and t.deal_status='已结账' group by t.get_time) t1 left join " + "(select b.recharge_people as recharge_people," +
                "b.document_number as  document_number,group_concat(distinct b.checkout_method) as checkout_method, b.operation_time as operation_time from (" + rechargeTables + ") b " +
                "group by b.operation_time) t2 on t1.get_time = t2.operation_time order by t1.get_time desc";
        List<PayServicedInfo> payServiceList = sqlMapper.selectList(sql, PayServicedInfo.class);
        return payServiceList;
    }

    public List<IconInfo> getCurrentList(String num, String reservationsId) throws Exception {
        if (ToolUtil.isEmpty(num)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String sql = "select t1.id as id,t1.outpatient_name as outpatientName,t1.add_time as addTime,t1.add_name as addName,t1.customer_name as customerName," +
                "t1.remarks as remarks,t1.image_url as imageUrl,t1.status as status,t1.score as score,t1.cause as cause,t1.num as num from icon_infos t1  where t1.num='" + num + "' and t1.reservations_id " +
                "= '" + reservationsId + "'  order by t1.icon_name1 desc";
        List<IconInfo> currentList = sqlMapper.selectList(sql, IconInfo.class);
        return currentList;
    }

    /**
     * 医生的成交记录
     *
     * @param operationTime
     * @param reservationsId
     * @param
     * @return
     */
    @RequestMapping(value = "/getOpenBillListRecord", method = RequestMethod.POST)
    @ResponseBody
    public List<PayServicedInfo> getOpenBillLisHuajia(String operationTime, String reservationsId) {
        if (StringUtil.isNotEmpty(operationTime) && operationTime.length() == 18) {//yyyy-mm-ddHH:mm:ss --- yyyy-mm-dd HH:mm:ss
            operationTime = operationTime.substring(0, 10) + " " + operationTime.substring(10);//中间加入空格
        }
        String sql3 = "SELECT  service_actual_pay  as serviceActualPay, arrears as  arrears, " +
                " t1.id AS id,t1.customer_id AS customerId,t1.reservations_id AS reservationsId,left(t1.get_time,19) AS getTime,t1.outpatient_name AS outpatientName, " +
                " t1.deal_status AS dealStatus, t1.tc_name AS tcName,t1.pay_service_num AS payServiceNum,t4.recharge_people as rechargePeople,t4.remarks as remarkss," +
                " LEFT(t1.operation_time,19) AS operationTime,t1.remarks AS remarks, t1.folding_pay AS foldingPay,t1.doctor AS doctor," +
                "(case " +
                "  when t1.is_do=1 then '不做了'" +
                "  when t1.is_do=2 then '继续做'" +
                "  when t1.is_do=3 then '还欠款'" +
                "  when t1.is_do=4 then '退款'" +
                "  when t1.is_do=5 then '消费'" +
                "  when t1.is_do=6 then '作废'" +
                "  end " +
                "  ) isDoName," +
                " t2.department AS department,t2.first_level_project AS firstLevelProject,t2.pay_service_name AS payServiceName, t2.pay_service_price_one AS payServicePriceOne, " +
                " t2.pay_service_price_two AS payServicePriceTwo,t3.customer_name AS customerName," +
                " t3.medical_record_number AS medicalRecordNumber,t3.customer_phone AS customerPhone,t3.customer_age AS customerAge,t1.id2,t3.arrival_store AS arrivalStore,t1.tc_name AS fieldTc,t1.check_status AS checkStatus,t4.checkout_method as checkoutMethod " +
                " from " + ShiroKit.getUser().getDeal_info() + " t1 left join " + ShiroKit.getUser().getPay_service_info() + " t2 on t1.pay_service_id=t2.id left join " + ShiroKit.getUser().getCustomer_info() + " t3 on t1.customer_id=t3.id" +
                " left join " + ShiroKit.getUser().getRecharge_info() + " t4 on t4.id2=t1.id where t1.operation_time='" + operationTime + "' " +
                " and t1.reservations_id='" + reservationsId + "' " +
                " and t1.deal_status='已结账'order by t1.get_time desc ";
        List<PayServicedInfo> openBillList3 = sqlMapper.selectList(sql3, PayServicedInfo.class);
        Double totleReceivable = 0.00;//总的项目总价,非折后
        Double totleServiceActualPays = 0.00;//总的实付金额（除去不做的）
        Double totleFoldingPay = 0.00;//总的折后价
        Double accountArrears = 0.00;
        for (PayServicedInfo info : openBillList3) {
            if (info != null) {
                if (info.getPayServiceId() != null && info.getPayServiceId() != "") {
                    if (info.getPayServiceNum() != null) {
                        totleReceivable += (info.getPayServicePriceTwo()) * (info.getPayServiceNum());
                    }
                    if (info.getFoldingPay() != null) {
                        totleFoldingPay += info.getFoldingPay();
                    }
                    if (info.getArrears() != null) {
                        accountArrears += info.getArrears();
                    }
                    if (info.getServiceActualPay() != null) {
                        totleServiceActualPays += info.getServiceActualPay();
                    }
                    info.setTotleReceivable(totleReceivable);
                    info.setTotleFoldingPay(totleFoldingPay);
                    info.setTotleServiceActualPay(totleServiceActualPays);
                    info.setAccountArrears(accountArrears);
                }
            }
        }
        return openBillList3;
    }

    /**
     * 点击病历 显示客户病历信息
     *
     * @param id
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/case_info/{id}")
    public String caseInfo(@PathVariable String id, Model model) throws Exception {
        if (ToolUtil.isEmpty(id)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        CustomerInfo customerInfo = customerService.selectOneById(id);
        //病例记录
        //1、先查询当前客户的所有病例记录
        String caseInfoSql = "select LEFT(t1.finnally_time,19) as finnallyTime1 ,t1.* from case_info t1  where t1.reservations_id='" + customerInfo.getReservationsId() + "'order by t1.finnally_time desc";
        List<CaseInfo> caseInfoList = sqlMapper.selectList(caseInfoSql, CaseInfo.class);
        for (CaseInfo infos : caseInfoList) {
            if (infos != null) {
                if (infos.getOperationTime() != "" && infos.getOperationTime() != null) {
                    infos.setOperationTime(infos.getOperationTime().substring(0, 10));
                }
                if (infos.getFinnallyTime() != "" && infos.getFinnallyTime() != null) {
                    infos.setFinnallyTime(infos.getFinnallyTime().substring(0, 19));
                }
                String sql3 = "select pay_service_name as payServiceName from " + ShiroKit.getUser().getPay_service_info() + " where id ='" + infos.getPayServiceId() + "' limit 1";
                CaseInfo caseInfo1 = sqlMapper.selectOne(sql3, CaseInfo.class);
                if (caseInfo1 == null) {
                    continue;
                }
                infos.setPayServiceName(caseInfo1.getPayServiceName());
            }
        }
        //2.循环遍历每个病例记录,给对应病例的牙位属性赋值
        for (CaseInfo caseInfo : caseInfoList) {
            //然后查询牙位集合
            String toothSIteSql = "select * from tooth_site t1 where t1.case_id='" + caseInfo.getId() + "' ";
            List<ToothSite> toothSiteList = sqlMapper.selectList(toothSIteSql, ToothSite.class);
            for (ToothSite toothSite : toothSiteList) {
                //根据对应的牙位类型,给病例实体的对应牙位属性赋值
                if (toothSite.getYaType().equals("1")) {
                    caseInfo.getToothSite1List().add(toothSite);
                }
                if (toothSite.getYaType().equals("2")) {
                    caseInfo.getToothSite2List().add(toothSite);
                }
                if (toothSite.getYaType().equals("3")) {
                    caseInfo.getToothSite3List().add(toothSite);
                }
                if (toothSite.getYaType().equals("4")) {
                    caseInfo.getToothSite4List().add(toothSite);
                }
                if (toothSite.getYaType().equals("5")) {
                    caseInfo.getToothSite5List().add(toothSite);
                }
            }
        }
        //患者信息
        String sql1 = " select " +
                "  (CASE a.customer_sex " +
                "  WHEN 1 THEN " +
                "  '男' " +
                "  WHEN 2 THEN " +
                "  '女' " +
                "  ELSE " +
                "  '未知' " +
                "  END " +
                " ) as sex ,a.* from " + ShiroKit.getUser().getCustomer_info() + " a where id='" + id + "' limit 1";
        ConsultantInfo consultantInfo = sqlMapper.selectOne(sql1, ConsultantInfo.class);
        model.addAttribute("reservationsId", customerInfo.getReservationsId());  //预约ID
        model.addAttribute("customerId", id);  //客户ID
        model.addAttribute("customerInfo", customerInfo);
        model.addAttribute("caseInfoList", caseInfoList);
        model.addAttribute("consultantInfo", consultantInfo);
        model.addAttribute("userName", ShiroKit.getUser().getAccount());
        return PREFIX + "customer_case_info.html";
    }

    /**
     * 点击收费  显示客户成交记录
     *
     * @param id
     * @param model
     * @throws Exception
     * @returncharge_info
     */
    @RequestMapping(value = "/charge_info/{id}")
    public String chargeInfo1(@PathVariable String id, Model model) throws Exception {
        if (ToolUtil.isEmpty(id)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        CustomerInfo customerInfo = customerService.selectOneById(id);
        //通过预约ID  获得收费记录
        String sql = "select t1.id as id,t1.id2 as id2,t1.customer_id as customerId,t1.reservations_id as reservationsId ,t1.outpatient_name as outpatientName , t1.deal_status  as dealStatus,t1.pay_service_num as payServiceNum ," +
                " t1.service_actual_pay as serviceActualPay ,left(t1.operation_time,19) as operationTime,left(t3.recharge_time,19) as rechargeTime,t1.remarks as remarks," +
                " t1.arrears as arrears,t2.pay_service_name as payServiceName,left(t1.get_time,19) as getTime from " + ShiroKit.getUser().getDeal_info() + " t1 left join " + ShiroKit.getUser().getPay_service_info() + " t2 on t1.pay_service_id=t2.id left join " + ShiroKit.getUser().getRecharge_info() + " t3 on t3.id2=t1.id2 " +
                " where t1.reservations_id='" + customerInfo.getReservationsId() + "' and  t1.deal_status ='已结账'  group by  operationTime order by operationTime desc";
        List<PayServicedInfo> payServiceInfoList = sqlMapper.selectList(sql, PayServicedInfo.class);
        Double totleReceivable = 0.00;
        Double totleFoldingPay = 0.00;   //
        Double totleServiceActualPay = 0.00; //总实收
        Double accountArrears = 0.00;  //总欠款
        for (PayServicedInfo info : payServiceInfoList) {
            if (info != null) {
                if (info.getPayServiceId() != null && info.getPayServiceId() != "") {
                    if (info.getFoldingPay() != null) {
                        totleFoldingPay += info.getFoldingPay();
                    }
                    //总实收
                    if (info.getServiceActualPay() != null) {
                        totleServiceActualPay += info.getServiceActualPay();
                    }
                    //总欠款
                    if (info.getArrears() != null) {
                        accountArrears += info.getArrears();
                    }
                    info.setTotleReceivable(totleReceivable);
                    info.setTotleFoldingPay(totleFoldingPay);
                    info.setTotleServiceActualPay(totleServiceActualPay);
                    info.setAccountArrears(accountArrears);
                }
                if (info.getOperationTime() != "" && info.getOperationTime() != null) {
                    info.setOperationTimeOne(info.getOperationTime().substring(0, 10));
                    info.setOperationTimeTwo(info.getOperationTime().substring(11, info.getOperationTime().length()));
                }
                if (info.getRechargeTime() != "" && info.getRechargeTime() != null) {
                    info.setRechargeTimeOne(info.getRechargeTime().substring(0, 10));
                    info.setRechargeTimeTwo(info.getRechargeTime().substring(11, info.getRechargeTime().length()));
                }
            }
        }
        //患者详情
        String sql1 = " select " +
                "  (CASE a.customer_sex " +
                "  WHEN 1 THEN " +
                "  '男' " +
                "  WHEN 2 THEN " +
                "  '女' " +
                "  ELSE " +
                "  '未知' " +
                "  END " +
                " ) as sex ,a.* from " + ShiroKit.getUser().getCustomer_info() + " a where id='" + id + "' limit 1";
        ConsultantInfo consultantInfo = sqlMapper.selectOne(sql1, ConsultantInfo.class);
        model.addAttribute("reservationsId", customerInfo.getReservationsId());  //预约ID
        model.addAttribute("customerId", id);  //客户ID
        model.addAttribute("customerInfo", customerInfo);
        model.addAttribute("consultantInfo", consultantInfo);
        model.addAttribute("userName", ShiroKit.getUser().getAccount());
        model.addAttribute("payServiceInfoList", payServiceInfoList);
        return PREFIX + "customer_charge_info.html";
    }

    /**
     * 医生划价 插入  传入属性(项目,预约ID 状态,)
     */
    @RequestMapping("/")
    @ResponseBody
    public String insertChangePriceInfo() {
        return "";
    }

    /**
     * 查询 划价的记录
     *
     * @param reservationsId
     * @return
     */
    @RequestMapping(value = "/getOpenBillListf", method = RequestMethod.POST)
    @ResponseBody
    public List<PayServicedInfo> getOpenBillListf(String operationTime, String reservationsId) {
        if (StringUtil.isNotEmpty(operationTime) && operationTime.length() == 18) {//yyyy-mm-ddHH:mm:ss --- yyyy-mm-dd HH:mm:ss
            operationTime = operationTime.substring(0, 10) + " " + operationTime.substring(10);//中间加入空格deposit_amount
        }
        //医生划价数据,剩余可划扣实收=结账表实收-业绩表实收  业绩=结账表实收+(结账表积分金额  满足 结账方式如果= 付款方式表ID 中是否记录医生业绩表字段值为1  才加入计算)
        String sql3 = "SELECT IFNULL(t2.folding_pay,0) - IFNULL(t2.deduction_amount,0) AS totalPerformance," +
                " IFNULL(t2.serviceActualPay,0) - IFNULL(t3.serviceActualPay,0) + IFNULL(t2.deposit_amount, 0) as serviceActualPay," +
                "IFNULL(t2.deduction_amounts,0)-IFNULL(t3.deduction,0) AS deductionAmount," +
                "t2.deposit_amount1 as depositAmount1,t2.deduction_amount1 as deductionAmount1,t2.folding_pay AS foldingPay," +
                "t2.arrears as accountArrears,t2.id AS id,t2.customer_id AS customerId,t2.reservations_id AS reservationsId," +
                "t2.get_time AS getTime,t1.rechargeTime,t2.deal_status AS dealStatus,t2.pay_service_num AS payServiceNum," +
                "LEFT(t2.operation_time,19) AS operationTime,t2.remarks AS remarks,t2.doctor AS doctor,t2.left_up AS leftUp," +
                "t2.left_down AS leftDown,t2.right_up AS rightUp,t2.right_down AS rightDown,t2.execute_status as executeStatus," +
                "t2.id2,t4.pay_service_name as payServiceName from (SELECT SUM(w.service_actual_pay) AS serviceActualPay," +
                "sum(IF (c.charge_bill_is_docAchievement = 1,0,w.deduction_amount)) AS deduction_amount," +
                "sum(IF (c.charge_bill_is_docAchievement = 1,w.deduction_amount,0)) AS deduction_amounts," +
                "SUM(w.deposit_amount) AS deposit_amount," +
                "SUM(w.arrears) AS arrears,w.id2,w.id,w.customer_id,SUM(w.folding_pay+IF(w.is_do='4',arrears,0)) as folding_pay," +
                "w.deduction_amount as deduction_amount1,w.deposit_amount as deposit_amount1,w.get_time,w.deal_status," +
                "w.pay_service_num,w.reservations_id,w.operation_time,w.remarks,w.doctor,w.left_up,w.left_down,w.right_up," +
                "w.pay_service_id,w.right_down,w.execute_status FROM " + ShiroKit.getUser().getDeal_info() + " w left join checkout_method_info c on c.id = w.deduction_type WHERE " +
                "w.reservations_id = '" + reservationsId + "' AND w.operation_time='" + operationTime + "' " +
                "AND w.deal_status = '已结账' GROUP BY w.id2) t2 left join (SELECT min(w.recharge_time) AS rechargeTime," +
                "w.id2,w.reservations_id FROM " + ShiroKit.getUser().getRecharge_info() + " w WHERE w.reservations_id = '" + reservationsId + "' " +
                "GROUP BY id2) t1 on t2.id2=t1.id2 left join (select SUM(d.service_actual_pay) as serviceActualPay,SUM(d.deduction) as deduction," +
                "id2 from doctor_change_price d where d.status='1' and d.reservations_id ='" + reservationsId + "' group by id2) t3 " +
                "ON t1.id2 = t3.id2 left join " + ShiroKit.getUser().getPay_service_info() + " t4 on t2.pay_service_id=t4.id where 1=1 ";
        List<PayServicedInfo> openBillList3 = sqlMapper.selectList(sql3, PayServicedInfo.class);
        return openBillList3;
    }

    /**
     * 点击随访  显示客户随访记录
     *
     * @param id
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/revisit_info/{id}")
    public String revisitInfo(@PathVariable String id, Model model) throws Exception {
        if (ToolUtil.isEmpty(id)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        //患者详情
        String sql1 = " select " +
                "  (CASE a.customer_sex " +
                "  WHEN 1 THEN " +
                "  '男' " +
                "  WHEN 2 THEN " +
                "  '女' " +
                "  ELSE " +
                "  '未知' " +
                "  END " +
                " ) as sex ,a.* from " + ShiroKit.getUser().getCustomer_info() + " a where id='" + id + "' limit 1";
        ConsultantInfo consultantInfo = sqlMapper.selectOne(sql1, ConsultantInfo.class);
        //随访记录
        String sql4 = "select r.id,r.reservations_id,r.customer_id,r.revisit,r.revisit_time,r.outpatient_name,r.revisit_content,r.doctor,r.revisit_status," +
                "r.remarks  from return_doctor_visit_info r where r.reservations_id ='" + consultantInfo.getReservationsId() + "' ";
        List<DoctorRevisitInfo> doctorRevisitInfo = sqlMapper.selectList(sql4, DoctorRevisitInfo.class);
        //病例记录
        //1、先查询当前客户的所有病例记录
        String caseInfoSql = "select left(t1.finnally_time,19) as finnallyTime1,t1.* from case_info t1  " +
                "where t1.reservations_id='" + consultantInfo.getReservationsId() + "'order by t1.finnally_time desc";
        List<CaseInfo> caseInfoList = sqlMapper.selectList(caseInfoSql, CaseInfo.class);
        for (CaseInfo infos : caseInfoList) {
            if (infos != null) {
                if (infos.getOperationTime() != "" && infos.getOperationTime() != null) {
                    infos.setOperationTime(infos.getOperationTime().substring(0, 10));
                }
                String sql3 = "select pay_service_name as payServiceName from " + ShiroKit.getUser().getPay_service_info() + " where id ='" + infos.getPayServiceId() + "' limit 1";
                CaseInfo caseInfo1 = sqlMapper.selectOne(sql3, CaseInfo.class);
                if (caseInfo1 == null) {
                    continue;
                }
                infos.setPayServiceName(caseInfo1.getPayServiceName());
            }
        }
        //2.循环遍历每个病例记录,给对应病例的牙位属性赋值
        for (CaseInfo caseInfo : caseInfoList) { //然后查询牙位集合
            String toothSIteSql = "select * from tooth_site t1 where t1.case_id='" + caseInfo.getId() + "' ";
            List<ToothSite> toothSiteList = sqlMapper.selectList(toothSIteSql, ToothSite.class);
            for (ToothSite toothSite : toothSiteList) {
                //根据对应的牙位类型,给病例实体的对应牙位属性赋值
                if (toothSite.getYaType().equals("1")) {
                    caseInfo.getToothSite1List().add(toothSite);
                }
                if (toothSite.getYaType().equals("2")) {
                    caseInfo.getToothSite2List().add(toothSite);
                }
                if (toothSite.getYaType().equals("3")) {
                    caseInfo.getToothSite3List().add(toothSite);
                }
                if (toothSite.getYaType().equals("4")) {
                    caseInfo.getToothSite4List().add(toothSite);
                }
                if (toothSite.getYaType().equals("5")) {
                    caseInfo.getToothSite5List().add(toothSite);
                }
            }
        }
        if (ShiroKit.getUser().getDoctorInfoList() == null) {
            String doctorListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + ShiroKit.getUser().getAbbreviation() + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            List<DoctorInfo> doctorInfoList=sqlMapper.selectList(doctorListSql,DoctorInfo.class);
            ShiroKit.getUser().setDoctorInfoList(doctorInfoList);
        }
        model.addAttribute("doctorList", ShiroKit.getUser().getDoctorInfoList());
        model.addAttribute("reservationsId", consultantInfo.getReservationsId());  //预约ID
        model.addAttribute("customerId", id);  //客户ID
        model.addAttribute("customerInfo", consultantInfo);
        model.addAttribute("doctorRevisitInfo", doctorRevisitInfo);
        model.addAttribute("consultantInfo", consultantInfo);
        model.addAttribute("caseInfoList", caseInfoList);
        model.addAttribute("userName", ShiroKit.getUser().getAccount());
        return PREFIX + "customer_revisit.html";
    }

    /**
     * 点击复诊预约 customerId
     */
    @RequestMapping("/subsequent_info/{id}/{isFz}")
    public String subsequentInfo(@PathVariable String id, @PathVariable String isFz, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        CustomerInfo customerInfo = customerService.selectOneById(id);
        if (ShiroKit.getUser().getTcList() == null) {
            String getListSql = " select a.id as id,a.account as tcName from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on a.roleid=c.id " +
                    " where b.abbreviation='"+tableHead+"' and c.name like CONCAT('%','tc','%') ";
            List<TcInfo> tcList =sqlMapper.selectList(getListSql,TcInfo.class);
            ShiroKit.getUser().setTcList(tcList);
        }
        if (ShiroKit.getUser().getDoctorInfoList() == null) {
            String doctorListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + ShiroKit.getUser().getAbbreviation() + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            List<DoctorInfo> doctorInfoList=sqlMapper.selectList(doctorListSql,DoctorInfo.class);
            ShiroKit.getUser().setDoctorInfoList(doctorInfoList);
        }
        model.addAttribute("doctorList", ShiroKit.getUser().getDoctorInfoList());
        if (ShiroKit.getUser().getDepartmentList() == null) {
            String getListSql = "select a.department as department from " + ShiroKit.getUser().getPay_service_grade_info() + " a where a.is_upper=1 group by a.department order by a.id;";
            List<DepartmentInfo> departmentList=sqlMapper.selectList(getListSql,DepartmentInfo.class);
            ShiroKit.getUser().setDepartmentList(departmentList);
        }
        model.addAttribute("departmentList",ShiroKit.getUser().getDepartmentList());
        model.addAttribute("tcList", ShiroKit.getUser().getTcList());
        model.addAttribute("doctor", customerInfo.getDoctor());
        model.addAttribute("customerInfo", customerInfo);
        model.addAttribute("isFz", isFz);  //1：复诊到店,2：复诊预约
        return PREFIX + "doctor_appointments.html";
    }

    /**
     * 点击复诊预约 reservationsId isFz
     */
    @RequestMapping("/subsequent_info2/{reservationsId}/{isFz}")
    public String subsequent_info2(@PathVariable String reservationsId, @PathVariable String isFz, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        String sql1 = "select *  from " + ShiroKit.getUser().getCustomer_info() + " t where arrival_status!=1 and arrival_status!=6 and arrival_status!=7 and arrival_status!=8 and arrival_status!=9 " +
                " and arrival_status!=10 and reservations_id ='" + reservationsId + "' order by arrival_time desc  limit 0,1 ";
        CustomerInfo customerInfo = sqlMapper.selectOne(sql1, CustomerInfo.class);//匹配点复诊传过来的为预约id
        if (customerInfo == null) {       // 去另外一家店复诊,查到去的哪家店
            String sqld = "select id,abbreviation from distinction_customer_status where reservations_id ='" + reservationsId + "' and status=1  order by add_time limit 0,1 ";
            Dept cinfo = sqlMapper.selectOne(sqld, Dept.class);
            String sql2 = "select * from " + cinfo.getAbbreviation() + "customer_info t where reservations_id ='" + reservationsId + "' order by arrival_time desc  limit 0,1 ";
            customerInfo = sqlMapper.selectOne(sql2, CustomerInfo.class);
            customerInfo.setAbbreviation(cinfo.getAbbreviation());
        }
        if (ShiroKit.getUser().getTcList() == null) {
            String getListSql = " select a.id as id,a.account as tcName from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on a.roleid=c.id " +
                    " where b.abbreviation='"+tableHead+"' and c.name like CONCAT('%','tc','%') ";
            List<TcInfo> tcList =sqlMapper.selectList(getListSql,TcInfo.class);
            ShiroKit.getUser().setTcList(tcList);
        }
        if (ShiroKit.getUser().getDoctorInfoList() == null) {
            String doctorListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + ShiroKit.getUser().getAbbreviation() + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            List<DoctorInfo> doctorInfoList=sqlMapper.selectList(doctorListSql,DoctorInfo.class);
            ShiroKit.getUser().setDoctorInfoList(doctorInfoList);
        }
        model.addAttribute("doctorList", ShiroKit.getUser().getDoctorInfoList());
        if (ShiroKit.getUser().getDepartmentList() == null) {
            String getListSql = "select a.department as department from " + ShiroKit.getUser().getPay_service_grade_info() + " a where a.is_upper=1 group by a.department order by a.id;";
            List<DepartmentInfo> departmentList=sqlMapper.selectList(getListSql,DepartmentInfo.class);
            ShiroKit.getUser().setDepartmentList(departmentList);
        }
        model.addAttribute("departmentList",ShiroKit.getUser().getDepartmentList());
        model.addAttribute("tcList", ShiroKit.getUser().getTcList());
        model.addAttribute("doctor", customerInfo.getDoctor());
        model.addAttribute("customerInfo", customerInfo);
        model.addAttribute("isFz", isFz);  //1：复诊到店,2：复诊预约
        return PREFIX + "doctor_appointments2.html";
    }

    /**
     * 点击接诊 customerId
     */
    @RequestMapping("/receiveTreatment/{id}")
    public String receiveTreatment(@PathVariable String id, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        //客户信息
        CustomerInfo customerInfo = customerService.selectOneById(id);
        customerInfo.setStartTime(customerInfo.getStartTime().substring(11, 16));
        customerInfo.setEndTime(customerInfo.getEndTime().substring(11, 16));
        if (ShiroKit.getUser().getDoctorInfoList() == null) {
            String doctorListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + ShiroKit.getUser().getAbbreviation() + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            List<DoctorInfo> doctorInfoList=sqlMapper.selectList(doctorListSql,DoctorInfo.class);
            ShiroKit.getUser().setDoctorInfoList(doctorInfoList);
        }
        model.addAttribute("doctorList", ShiroKit.getUser().getDoctorInfoList());
        model.addAttribute("doctor", customerInfo.getDoctor());
        model.addAttribute("customerInfo", customerInfo);
        return PREFIX + "receiveTreatment_info.html";
    }

    /**
     * 点击影像 customerId
     */
    @RequestMapping("/image_info/{id}")
    public String imageInfo(@PathVariable String id, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        CustomerInfo customerInfo = customerService.selectOneById(id);
        //患者详情
        String sql1 = " select " +
                "  (CASE a.customer_sex " +
                "  WHEN 1 THEN " +
                "  '男' " +
                "  WHEN 2 THEN " +
                "  '女' " +
                "  ELSE " +
                "  '未知' " +
                "  END " +
                " ) as sex ,a.* from " + ShiroKit.getUser().getCustomer_info() + " a where id='" + id + "' limit 1";
        ConsultantInfo consultantInfo = sqlMapper.selectOne(sql1, ConsultantInfo.class);
        model.addAttribute("doctor", customerInfo.getDoctor());
        model.addAttribute("customerInfo", customerInfo);
        model.addAttribute("customerId", id);
        model.addAttribute("consultantInfo", consultantInfo);
        model.addAttribute("userName", ShiroKit.getUser().getAccount());
        return PREFIX + "customer_image_info.html";
    }

    /**
     * 点击随访表格 操作按钮
     */
    @RequestMapping(value = "/doctor_follow/{ids}")
    public String consultant(@PathVariable String ids, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        String id = ids.split(",")[0];
        String reservationsId = ids.split(",")[1];
        String customerId = ids.split(",")[2];
        String revisitTime = ids.split(",")[3];
        if (ToolUtil.isEmpty(customerId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        if (ToolUtil.isEmpty(reservationsId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        if (ToolUtil.isEmpty(revisitTime)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String sql1 = "select  t2.id as id,t2.customer_name as customerName,t2.reservations_id as reservationsId,t2.medical_record_number as medicalRecordNumber,t2.doctor as doctor," +
                "  (CASE t2.customer_sex  " +
                "  WHEN 1 THEN  " +
                "  '男'  " +
                "  WHEN 2 THEN  " +
                "  '女'  " +
                "  ELSE  " +
                "  '未知'  " +
                "  END  " +
                " ) as sex ,t2.customer_age as customerAge,t2.customer_phone as customerPhone ,t2.field_tc as fieldTc,t2.one_channel as oneChannel,t1.first_visit_date as firstVisitDate" +
                " from " + ShiroKit.getUser().getCustomer_info() + " t2 left join reservations_info t1 on t1.id = t2.reservations_id where t2.id='" + customerId + "' limit 1";
        ConsultantInfo consultantInfo = sqlMapper.selectOne(sql1, ConsultantInfo.class);
        String sql2 = "select r.id,r.reservations_id,r.customer_id,r.revisit,left(r.revisit_time,10) as revisitTime,r.outpatient_name," +
                " r.revisit_content,r.doctor,r.revisit_status,r.remarks  from return_doctor_visit_info r " +
                " where  r.revisit_time ='" + revisitTime + "' and id='" + id + "' limit 1";
        DoctorRevisitInfo doctorRevisitInfo = sqlMapper.selectOne(sql2, DoctorRevisitInfo.class);
        //随访记录
        String sql4 = "select r.id,r.reservations_id,r.customer_id,r.revisit,r.create_name,r.revisit_time,r.outpatient_name,r.revisit_content,r.doctor,r.revisit_status,r.remarks from return_doctor_visit_info r where r.customer_id ='" + customerId + "' ";
        List<DoctorRevisitInfo> doctorRevisitInfoList = sqlMapper.selectList(sql4, DoctorRevisitInfo.class);
        for (DoctorRevisitInfo info1 : doctorRevisitInfoList) {
            if (info1.getRevisitTime() != "" && info1.getRevisitTime() != null) {
                info1.setRevisitTime(info1.getRevisitTime().substring(0, 11));
            }
        }
        //病历记录
        String sql5 = "select left(t.create_appointment_time,19) as createAppointmentTime,left(t.start_time,19) as startTime,left(t.arrival_time,19) as arrivalTime,t.id as id," +
                "t.reservations_id as reservationsId,t.doctor as doctor,t.field_tc as fieldTc,t.remarks as remarks,t.remarks_reservation as remarksReservation," +
                "t.arrival_status as arrivalStatus," +
                "t.archiving as archiving,t.arrival_store as arrivalStore,t.customer_status as customerStatus,t.status as status,t.appointment_pay_service as appointmentPayService," +
                "t1.zhushu as zhushu,t1.remarkss as remarkss,t1.doctor_advice as doctorAdvice from " + ShiroKit.getUser().getCustomer_info() + " t " +
                "left join case_info t1 on t.id=t1.customer_id where t.reservations_id='" + reservationsId + "' " +
                " and t.arrival_status in (1,2,3,4,5,6,9,10) and t1.arrival_store='" + ShiroKit.getUser().getOutpatientName() + "' " +
                " order by start_time desc";
        List<DoctorDiagnosisInfo> DoctorDiagnosisInfoList = sqlMapper.selectList(sql5, DoctorDiagnosisInfo.class);
        if (ShiroKit.getUser().getDoctorInfoList() == null) {
            String doctorListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + ShiroKit.getUser().getAbbreviation() + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            List<DoctorInfo> doctorInfoList=sqlMapper.selectList(doctorListSql,DoctorInfo.class);
            ShiroKit.getUser().setDoctorInfoList(doctorInfoList);
        }
        model.addAttribute("doctorList", ShiroKit.getUser().getDoctorInfoList());
        model.addAttribute("consultantInfo", consultantInfo);
        model.addAttribute("doctorRevisitInfoList", doctorRevisitInfoList);  //随访记录
        model.addAttribute("DoctorDiagnosisInfoList", DoctorDiagnosisInfoList); //就诊记录
        model.addAttribute("doctorRevisitInfo", doctorRevisitInfo);
        model.addAttribute("createName", ShiroKit.getUser().getAccount());  //创建人
        model.addAttribute("customerId", customerId);
        model.addAttribute("arrivalStore", ShiroKit.getUser().getOutpatientName());  //门店
        return PREFIX + "doctor_followss.html";
    }

    /**
     * 编辑机加工
     */
    @RequestMapping(value = "/update_process/{ids}")
    public String updateProcess(@PathVariable String ids, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        if (ToolUtil.isEmpty(ids)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String sql1 = "select * from doctor_technology_processing where id='" + ids + "' limit 1";
        DoctorTechnologyProcessingInfo info = sqlMapper.selectOne(sql1, DoctorTechnologyProcessingInfo.class);
        if (ShiroKit.getUser().getDoctorInfoList() == null) {
            String doctorListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + ShiroKit.getUser().getAbbreviation() + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            List<DoctorInfo> doctorInfoList=sqlMapper.selectList(doctorListSql,DoctorInfo.class);
            ShiroKit.getUser().setDoctorInfoList(doctorInfoList);
        }
        model.addAttribute("doctorList", ShiroKit.getUser().getDoctorInfoList());
        if (ShiroKit.getSessionAttr("consumablesList") == null) {
            String getListSql = "select id,name as name,add_time as addTime,num as num from consumable_info ";
            List<ConsumablesNameInfo> listInfo = sqlMapper.selectList(getListSql, ConsumablesNameInfo.class);
            ShiroKit.setSessionAttr("consumablesList", listInfo);
        }
        model.addAttribute("outpatientManagementList", ShiroKit.getSessionAttr("outpatientManagementList"));
        model.addAttribute("info", info);
        model.addAttribute("id", info.getId());
        return PREFIX + "doctor_update_consumable.html";
    }

    /**
     * 编辑 耗材加工
     */
    @RequestMapping(value = "/update_tec/{ids}")
    public String updateTec(@PathVariable String ids, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        if (ToolUtil.isEmpty(ids)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String sql1 = "select * from doctor_consumable where id='" + ids + "' limit 1";
        DoctorTechnologyInfo info = sqlMapper.selectOne(sql1, DoctorTechnologyInfo.class);
        if (ShiroKit.getUser().getDoctorInfoList() == null) {
            String doctorListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + ShiroKit.getUser().getAbbreviation() + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            List<DoctorInfo> doctorInfoList=sqlMapper.selectList(doctorListSql,DoctorInfo.class);
            ShiroKit.getUser().setDoctorInfoList(doctorInfoList);
        }
        model.addAttribute("doctorList", ShiroKit.getUser().getDoctorInfoList());
        model.addAttribute("outpatientManagementList", ShiroKit.getSessionAttr("outpatientManagementList"));
        model.addAttribute("info", info);
        model.addAttribute("id", info.getId());
        return PREFIX + "doctor_process_update.html";
    }

    /**
     * 医生列表
     */
    @RequestMapping("/list")
    @ResponseBody
    public Object testrInfoList(SearchDoctorLookedInfo info, HttpServletRequest request) {
        Page<DoctorLookedInfo> page = new PageFactory<DoctorLookedInfo>().defaultPage();
        if (info.getAbbreviation() == "" || info.getAbbreviation() == null || info.getAbbreviation() == "null") {
            return null;
        } else {
            try {
                info.setStartIndex(page.getSize() * (page.getCurrent() - 1));
                info.setLimitIndex(page.getSize());
                page.setCurrent(0);
                List<DoctorLookedInfo> list = service.selectPageListByQueryGetMap(page, info);
                if (list.size() == 0) {
                    info.setStartIndex(0);
                    list = service.selectPageListByQueryGetMap(page, info);
                }
                page.setTotal(service.getQueryPagesCount(page, info));
                page.setRecords(list);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return super.packForBT(page);
        }
    }

    /**
     * 今日操作
     */
    @RequestMapping("/operationList")
    @ResponseBody
    public Object operationList(SearchDoctorOperationInfo info, HttpServletRequest request) {
        Page<DoctorOperationInfo> page = new PageFactory<DoctorOperationInfo>().defaultPage();
        if (info.getAbbreviation() == "" || info.getAbbreviation() == null) {
            return null;
        } else {
            try {
                info.setStartIndex(page.getSize() * (page.getCurrent() - 1));
                info.setLimitIndex(page.getSize());
                page.setCurrent(0);
                List<DoctorOperationInfo> list = service.selectDoctorGetMap(page, info);
                if (list.size() == 0) {
                    info.setStartIndex(0);
                    list = service.selectDoctorGetMap(page, info);
                }
                page.setTotal(service.getQueryPagesDoctorCount(page, info));
                page.setRecords(list);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return super.packForBT(page);
        }
    }

    /**
     * 耗材新增
     */
    @RequestMapping(value = "/ensure", method = RequestMethod.POST)
    @ResponseBody
    public int ensure(String customerId, String reservationsId, String[] str, String doctor, String remarks, HttpServletRequest request) {
        String leftUp = "";
        String leftDown = "";
        String rightUp = "";
        String rightDown = "";
        String consumableName = "";
        String arrivalStore = "";
        String number = "";
        String amount = "";
        String amountActually = "";
        String price = "";
        String type = "";
        for (int i = 0; i < str.length; i++) {
            leftUp = str[i].split("#")[0];
            rightUp = str[i].split("#")[1];
            rightDown = str[i].split("#")[2];
            leftDown = str[i].split("#")[3];
            consumableName = str[i].split("#")[4];
            arrivalStore = str[i].split("#")[5];
            number = str[i].split("#")[6];
            price = str[i].split("#")[7];
            amount = str[i].split("#")[8];
            amountActually = str[i].split("#")[9];
            type = str[i].split("#")[10];
            String sql1 = "select medical_record_number from " + ShiroKit.getUser().getCustomer_info() + " where id='" + customerId + "' limit 1";
            CustomerInfo info = sqlMapper.selectOne(sql1, CustomerInfo.class);
            String sql = " INSERT INTO doctor_consumable (customer_id,reservations_id,left_up,left_down, " +
                    " right_up,right_down, consumable_name,arrival_store,amount,amount_actually,number ,price,type, remarks, create_time,doctor,medical_record_number) values  " +
                    " ('" + customerId + "','" + reservationsId + "','" + leftUp + "','" + leftDown + "','" + rightUp + "', " +
                    " '" + rightDown + "','" + consumableName + "','" + arrivalStore + "','" + amount + "', '" + amountActually + "','" + number + "' ,'" + price + "','" + type + "'," +
                    " '" + remarks + "', '" + DateTimeKit.now() + "','" + doctor + "','" + info.getMedicalRecordNumber() + "') ";
            sqlMapper.insert(sql);
        }
        return 1;
    }

    /**
     * 机加工新增
     */
    @RequestMapping(value = "/ensure1", method = RequestMethod.POST)
    @ResponseBody
    public int checkOut(String customerId, String reservationsId, String[] str, String doctor, String remarks, String processUnit,
                        String status, String store, String picker, String phone, String deliveryTime, String pickUpTime, HttpServletRequest request) {
        String time = DateTimeKit.now().substring(0, 10).replace("-", "");
        Random rand = new Random();
        int randomNumber = rand.nextInt(999999);
        time = time + randomNumber;
        String leftUp = "";
        String leftDown = "";
        String rightUp = "";
        String rightDown = "";
        String payServiceName = "";
        String number = "";
        String amount = "";
        String amountActually = "";
        String price = "";
        String type = "";
        for (int i = 0; i < str.length; i++) {
            leftUp = str[i].split("#")[0];
            rightUp = str[i].split("#")[1];
            rightDown = str[i].split("#")[2];
            leftDown = str[i].split("#")[3];
            payServiceName = str[i].split("#")[4];
            number = str[i].split("#")[5];
            amount = str[i].split("#")[6];
            amountActually = str[i].split("#")[7];
            price = str[i].split("#")[8];
            type = str[i].split("#")[9];
            String sql1 = "select medical_record_number from " + ShiroKit.getUser().getCustomer_info() + " where id='" + customerId + "' limit 1";
            CustomerInfo info = sqlMapper.selectOne(sql1, CustomerInfo.class);
            String sql = " INSERT INTO doctor_technology_processing (order_number,customer_id,reservations_id,left_up,left_down, " +
                    " right_up,right_down,arrival_store, pay_service_name,amount,amount_actually,price,number ,type, remarks, create_time,doctor,process_unit,status,medical_record_number,picker,phone,delivery_time,pick_up_time) values  " +
                    " ('" + time + "','" + customerId + "','" + reservationsId + "','" + leftUp + "','" + leftDown + "','" + rightUp + "', " +
                    " '" + rightDown + "','" + store + "','" + payServiceName + "','" + amount + "','" + amountActually + "','" + price + "' ,'" + number + "' ,'" + type + "', " +
                    "'" + remarks + "', '" + DateTimeKit.now() + "','" + doctor + "','" + processUnit + "','" + status + "'," +
                    "'" + info.getMedicalRecordNumber() + "','" + picker + "','" + phone + "','" + deliveryTime + "','" + pickUpTime + "') ";
            sqlMapper.insert(sql);
        }
        return 1;
    }

    /**
     * 医生耗材列表数据processingTableList
     */
    @RequestMapping(value = "/technologyTableList/{reservationsId}")
    @ResponseBody
    public List<DoctorTechnologyInfo> technologyTableList(@PathVariable String reservationsId, Model model) throws
            Exception {
        if (ToolUtil.isEmpty(reservationsId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String sql = "select t.id as id,t.reservations_id as reservationsId,t.arrival_store as arrivalStore,t.amount_actually as amountActually,t.price as price,t.customer_id as customerId,left(t.create_time,19) as createTime,t.doctor as doctor,t.remarks as remarks," +
                "t.left_up as leftUp,t.right_up as rightUp,t.left_down as leftDown,t.right_down as rightDown,t.consumable_name as consumableName,t.amount as amount," +
                "t.number as number,t.type as type,r.customer_name as customerName from doctor_consumable t " +
                "left join " + ShiroKit.getUser().getCustomer_info() + " r on t.customer_id = r.id where t.reservations_id='" + reservationsId + "'";
        List<DoctorTechnologyInfo> list = sqlMapper.selectList(sql, DoctorTechnologyInfo.class);
        return list;
    }

    /**
     * 医生机加工列表数据processingTableList
     */
    @RequestMapping(value = "/processingTableList/{reservationsId}")
    @ResponseBody
    public List<DoctorTechnologyProcessingInfo> processingTableList(@PathVariable String reservationsId, Model model) throws
            Exception {
        if (ToolUtil.isEmpty(reservationsId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String sql = "select t.id as id,t.reservations_id as reservationsId,t.customer_id as customerId,t.price as price,t.amount_actually as amountActually,t.arrival_store as arrivalStore,t.status as status,left(t.create_time,19) as createTime,t.doctor as doctor,t.remarks as remarks," +
                "t.left_up as leftUp,t.right_up as rightUp,t.left_down as leftDown,t.right_down as rightDown,t.pay_service_name as payServiceName,t.amount as amount," +
                "t.number as number,t.type as type,t.discount_price as discountPrice ,t.process_unit as processUnit,r.customer_name as customerName from doctor_technology_processing t " +
                "left join " + ShiroKit.getUser().getCustomer_info() + " r on t.customer_id = r.id where t.reservations_id='" + reservationsId + "'";
        List<DoctorTechnologyProcessingInfo> list = sqlMapper.selectList(sql, DoctorTechnologyProcessingInfo.class);
        return list;
    }

    //机加工修改
    @RequestMapping(value = "/update_technology", method = RequestMethod.POST)
    @ResponseBody
    public int updateTechnology(String doctor, String id, String remarks, String leftUp, String rightUp, String leftDown, String rightDown, String arrivalStore, String payServiceName,
                                String number, Double price, String type, String processUnit, String status, Double amount, Double amountActually) {
        String sql = "select * from doctor_technology_processing where id='" + id + "' limit 1";
        DoctorTechnologyProcessingInfo info = sqlMapper.selectOne(sql, DoctorTechnologyProcessingInfo.class);
        if (leftUp == null || leftUp == "") {
            leftUp = info.getLeftUp();
        }
        if (rightUp == null || rightUp == "") {
            rightUp = info.getRightUp();
        }
        if (leftDown == null || leftDown == "") {
            leftDown = info.getLeftDown();
        }
        if (rightDown == null || rightDown == "") {
            rightDown = info.getRightDown();
        }
        if (remarks == null || remarks == "") {
            remarks = info.getRemarks();
        }

        String sql1 = "update doctor_technology_processing t set t.doctor='" + doctor + "',t.remarks='" + remarks + "',t.left_up='" + leftUp + "',t.right_up='" + rightUp + "',t.left_down='" + leftDown + "'," +
                "t.right_down='" + rightDown + "',t.arrival_store='" + arrivalStore + "',t.pay_service_name='" + payServiceName + "',t.amount='" + amount + "',t.price='" + price + "'," +
                "t.number='" + number + "',t.type='" + type + "',t.process_unit='" + processUnit + "',t.amount_actually='" + amountActually + "',t.status='" + status + "' where id='" + id + "'";
        return sqlMapper.update(sql1);
    }

    //耗材修改修改
    @RequestMapping(value = "/update_consumable", method = RequestMethod.POST)
    @ResponseBody
    public int updateConsumable(String doctor, String id, String remarks, String leftUp, String rightUp, String leftDown, String rightDown, String arrivalStore, String consumableName,
                                String number, String type, Double price, Double amount, Double amountActually) {
        String sql = "select * from doctor_consumable where id='" + id + "' limit 1";
        DoctorTechnologyInfo info = sqlMapper.selectOne(sql, DoctorTechnologyInfo.class);
        if (leftUp == null || leftUp == "") {
            leftUp = info.getLeftUp();
        }
        if (rightUp == null || rightUp == "") {
            rightUp = info.getRightUp();
        }
        if (leftDown == null || leftDown == "") {
            leftDown = info.getLeftDown();
        }
        if (rightDown == null || rightDown == "") {
            rightDown = info.getRightDown();
        }
        if (doctor == null || doctor == "") {
            doctor = info.getDoctor();
        }
        if (remarks == null || remarks == "") {
            remarks = info.getRemarks();
        }
        String sql1 = "update doctor_consumable t set t.doctor='" + doctor + "',t.remarks='" + remarks + "',t.left_up='" + leftUp + "',t.right_up='" + rightUp + "',t.left_down='" + leftDown + "'," +
                "t.right_down='" + rightDown + "',t.arrival_store='" + arrivalStore + "',t.consumable_name='" + consumableName + "',t.amount_actually='" + amountActually + "',t.amount='" + amount + "'," +
                "t.number='" + number + "',t.price ='" + price + "' ,t.type='" + type + "' where id='" + id + "'";
        return sqlMapper.update(sql1);
    }

    /**
     * 删除机加工
     */
    @RequestMapping(value = "/delete_process")
    @ResponseBody
    public int deleteProcess(String ids, Model model) {
        if (ToolUtil.isEmpty(ids)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String sql1 = "delete from doctor_technology_processing where id='" + ids + "'";
        return sqlMapper.delete(sql1);
    }

    /**
     * 删除耗材
     */
    @RequestMapping(value = "/delete_tec")
    @ResponseBody
    public int deleteTec(String ids, Model model) {
        if (ToolUtil.isEmpty(ids)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String sql1 = "delete from doctor_consumable where id='" + ids + "'";
        return sqlMapper.delete(sql1);
    }

    /**
     * 医生业绩查询 表格
     */
    @RequestMapping("/queryList")
    @ResponseBody
    public Object queryList(SearchDoctorChangePriceInfo info, HttpServletRequest request) {
        Page<DoctorChangePriceInfo> page = new PageFactory<DoctorChangePriceInfo>().defaultPage();
        try {
            List<DoctorChangePriceInfo> list = new ArrayList<DoctorChangePriceInfo>();
            if ("executive".equals(info.getDimensionSelection())) {
                info.setStartIndex(page.getSize() * (page.getCurrent() - 1));
                info.setLimitIndex(page.getSize());
                page.setCurrent(0);
                list = service.selectDoctorPerformanceGetMap(page, info);
                if (list.size() == 0) {
                    info.setStartIndex(0);
                    list = service.selectDoctorPerformanceGetMap(page, info);
                }
                page.setTotal(service.getQueryPagesPerformanceCount(page, info));
                page.setRecords(list);
            } else if ("triage".equals(info.getDimensionSelection())) {
                info.setStartIndex(page.getSize() * (page.getCurrent() - 1));
                info.setLimitIndex(page.getSize());
                page.setCurrent(0);
                list = service.selectDoctorPerformanceGetFen(page, info);
                if (list.size() == 0) {
                    info.setStartIndex(0);
                    list = service.selectDoctorPerformanceGetFen(page, info);
                }
                page.setTotal(service.getQueryPagesCountFen(page, info));
                page.setRecords(list);
            }
            page.setRecords(list);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return super.packForBT(page);
    }

    /**
     * 跳转到病例列表主界面
     *
     * @return
     */
    @RequestMapping(value = "/caseInfoPage/{customerId}")
    public String caseInfoPage(@PathVariable String customerId, Model model) throws Exception {
        if (ToolUtil.isEmpty(customerId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        model.addAttribute("customerId", customerId);
        return PREFIX + "caseInfoPage.html";
    }

    /**
     * 查看客户的所有病例列表(表格ajax 组件请求)
     *
     * @param customerId 客户ID
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/caseTableList/{customerId}")
    @ResponseBody
    public List<CaseInfo> caseTableList(@PathVariable String customerId, Model model) throws Exception {
        if (ToolUtil.isEmpty(customerId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String sql = "select * from case_info c," + ShiroKit.getUser().getCustomer_info() + " w  where  c.customer_id = w.id and customer_id = '" + customerId + "' order by c.operation_time desc; ";
        List<CaseInfo> list = sqlMapper.selectList(sql, CaseInfo.class);
        return list;
    }

    /**
     * 医生回访数据列表
     */
    @RequestMapping(value = "/followTableList/{reservationsId}")
    @ResponseBody
    public List<DoctorRevisitInfo> FollowTableList(@PathVariable String reservationsId, Model model) throws Exception {
        if (ToolUtil.isEmpty(reservationsId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String sql = "select t.id as id,t.customer_id as customerId,t.reservations_id as reservationsId,t.revisit as revisit,t.revisit_time as revisitTime,t.outpatient_name as outpatientName,t.revisit_content as revisitContent,t.doctor as doctor,t.remarks as remarks," +
                "t.revisit_status as revisitStatus,t.create_name as createName,r.customer_name as customer_Name,r.arrival_store as arrivalStore,r.field_tc as fieldTc from return_doctor_visit_info t " +
                "left join " + ShiroKit.getUser().getCustomer_info() + " r on t.customer_id = r.id where t.reservations_id='" + reservationsId + "' order by t.revisit_time desc";
        List<DoctorRevisitInfo> list = sqlMapper.selectList(sql, DoctorRevisitInfo.class);
        return list;
    }

    /**
     * 删除回访
     */
    @RequestMapping(value = "/delete_revisit")
    @ResponseBody
    public int DeleteRevisit(String id, Model model) throws Exception {
        if (ToolUtil.isEmpty(id)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String selSql = "select * from return_doctor_visit_info where id='" + id + "' ";
        DoctorRevisitInfo info = sqlMapper.selectOne(selSql, DoctorRevisitInfo.class);
        if ((info.getRevisit()).equals(ShiroKit.getUser().getAccount()) || ShiroKit.getUser().getRoleName().indexOf("前台") != -1) {
            String sql = "delete from return_doctor_visit_info  where id = '" + id + "'";
            //插入随访日志
            String sq11 = "INSERT INTO `doctor_visit_info_log` (createtime,single_person,logtype, `userid`," +
                    " `succeed`,outpatient_name ,`message`,customer_id,reservations_id) VALUES " +
                    " ('" + DateTimeKit.now() + "','" + ShiroKit.getUser().getAccount() + "','删除随访','" + ShiroKit.getUser().getId() + "','成功','" + ShiroKit.getUser().getOutpatientName() +
                    "','删除时间：" + DateTimeKit.now() + "','" + info.getCustomerId() + "','" + info.getReservationsId() + "');";
            sqlMapper.insert(sq11);
            return sqlMapper.delete(sql);
        } else {
            return -1;
        }
    }

    /**
     * 跳转到添加病例界面
     *
     * @return
     */
    @RequestMapping(value = "/add_case/{cc}")
    public String addRecord(@PathVariable String cc, Model model) throws Exception {
        String customerId = cc.split(",")[0];
        if (ToolUtil.isEmpty(customerId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        if (ShiroKit.getUser().getDoctorInfoList() == null) {
            String doctorListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + ShiroKit.getUser().getAbbreviation() + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            List<DoctorInfo> doctorInfoList=sqlMapper.selectList(doctorListSql,DoctorInfo.class);
            ShiroKit.getUser().setDoctorInfoList(doctorInfoList);
        }
        model.addAttribute("doctorList", ShiroKit.getUser().getDoctorInfoList());
        ShiroKit.setSessionAttr("nursesList", null);
        if (ShiroKit.getSessionAttr("nursesList") == null) {
            String getListSql = " select a.id as id,a.name as nurse from user a left join dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on a.roleid=c.id " +
                    " where a.status='1' and (b.abbreviation='" + tableHead + "' and c.name in ('护士','护士长') and a.`status`='1')";
            ShiroKit.setSessionAttr("nursesList", sqlMapper.selectList(getListSql));
        }
        String selectsql = "select * from " + ShiroKit.getUser().getCustomer_info() + " where id='" + customerId + "' limit 1";
        CustomerInfo customerInfo = sqlMapper.selectOne(selectsql, CustomerInfo.class);
        if (customerInfo != null) {
            model.addAttribute("reservationsId", customerInfo.getReservationsId());
        }

        String sql2 = "select * from pay_service_grade_info";
        List<PayServicedInfo> payServiceInfo = sqlMapper.selectList(sql2, PayServicedInfo.class);
        //获得患者的到店时间
        String sql1 = "select left(arrival_time,19) as arrivalTime from " + ShiroKit.getUser().getCustomer_info() + " " +
                "where arrival_status!=1 and arrival_status!=6 and arrival_status!=7 and arrival_status!=8 and arrival_status!=9 and arrival_status!=10 and reservations_id = '" + customerInfo.getReservationsId() + "' and arrival_time is not null order by arrival_time DESC ";
        List<CustomerInfo> customerList = sqlMapper.selectList(sql1, CustomerInfo.class);
        //患者信息
        String sqlSelect = " select " +
                "  (CASE a.customer_sex " +
                "  WHEN 1 THEN " +
                "  '男' " +
                "  WHEN 2 THEN " +
                "  '女' " +
                "  ELSE " +
                "  '未知' " +
                "  END " +
                " ) as sex ,a.* from " + ShiroKit.getUser().getCustomer_info() + " a where id='" + customerId + "' limit 1";
        ConsultantInfo consultantInfo = sqlMapper.selectOne(sqlSelect, ConsultantInfo.class);
        model.addAttribute("nursesList", ShiroKit.getSessionAttr("nursesList"));
        model.addAttribute("userName", ShiroKit.getUser().getAccount());
        model.addAttribute("customerList", customerList);
        model.addAttribute("customerId", customerId);
        model.addAttribute("reservationsId", customerInfo.getReservationsId());
        model.addAttribute("payServiceInfo", payServiceInfo);
        model.addAttribute("consultantInfo", consultantInfo);
        return PREFIX + "medical_records.html";
    }

    /**
     * 病例数据添加
     *
     * @return
     */
    @RequestMapping(value = "/save")
    @ResponseBody
    public String add(CaseInfo info) throws Exception {
        info.setStatus(1);
        if (info.getArrivalStatus() != null) {
            customerService.updateCustomerArrivalStatus(info.getArrivalStatus(), info.getCustomerId());
        }
        return service.insert(info);
    }


    @RequestMapping(value = "/updateS", method = RequestMethod.POST)
    @ResponseBody
    public int updateStatusS(String id) throws Exception {
        String sql = "update case_info a set a.status='2' where id='" + id + "'";
        return sqlMapper.update(sql);
    }

    /**
     * 完成治疗
     *
     * @return
     */
    @RequestMapping(value = "/finshDraft")
    @ResponseBody
    public String finshDraft(CaseInfo info) throws Exception {
        info.setStatus(1);
        if (info.getArrivalStatus() != null) {
            customerService.updateCustomerArrivalStatus(info.getArrivalStatus(), info.getCustomerId());
        }
        return service.insert1(info);
    }

    /**
     * 病例数据添加草稿
     *
     * @return
     */
    @RequestMapping(value = "/saveDraft")
    @ResponseBody
    public String saveDraft(CaseInfo info) throws Exception {
        info.setStatus(2);
        return service.insert(info);
    }


    /**
     * 项目是否结束
     */
    @RequestMapping(value = "/doctor_statusic/{caseId}/{id}")
    public String doctor_statusic(@PathVariable String caseId, @PathVariable String id, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        model.addAttribute("caseId", caseId);
        model.addAttribute("customerId", id);
        return PREFIX + "doctor_statusic.html";
    }

    /**
     * 项目是否结束
     */
    @RequestMapping(value = "/update_doctor_statusic", method = RequestMethod.POST)
    @ResponseBody
    public int choiceTc(String caseId, String statusic) throws Exception {
        if (ToolUtil.isEmpty(caseId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String sq1 = "update case_info a set a.statusic='" + statusic + "' where id='" + caseId + "'";
        return sqlMapper.update(sq1);
    }

    /**
     * 统计查询
     */
    @RequestMapping(value = "/addBoLogValue", method = RequestMethod.POST)
    @ResponseBody
    public int addBoLogValue(String oneClass, String twoClass) throws Exception {
        String sql = "insert into ob_log(one_class,two_class) values('" + oneClass + "','" + twoClass + "')";
        return sqlMapper.insert(sql);
    }


    /**
     * 医生执行业绩统计
     */
    @RequestMapping(value = "/totalAccount", method = RequestMethod.GET)
    @ResponseBody
    public DoctorChangePriceInfo totalAccount(String param1, String param2, String param3, String param4, String treatmentUnit, String fieldTc, String doctor, String reach) throws Exception {
        String contitionInfo = "";
        if (StringUtils.isNotBlank(param1)) {
            contitionInfo += " and t.create_time >='" + param1 + "'";
        }
        if (StringUtils.isNotBlank(param2)) {
            contitionInfo += "and t.create_time <='" + param2 + "'";
        }
        if (StringUtils.isNotBlank(fieldTc)) {
            contitionInfo += " and t1.field_tc ='" + fieldTc + "'";
        }
        if (StringUtils.isNotBlank(treatmentUnit)) {
            contitionInfo += " and t1.treatment_unit ='" + treatmentUnit + "'";
        }
        if (StringUtils.isNotBlank(param4)) {
            contitionInfo += " and t1.appointment_pay_service ='" + param4 + "'";
        }
        if (StringUtils.isNotBlank(param3)) {
            contitionInfo += " and t1.arrival_store ='" + param3 + "'";
        }
        if (StringUtils.isNotBlank(reach)) {
            contitionInfo += " and (t1.customer_name like CONCAT('%','" + reach + "','%') or t1.customer_phone like CONCAT('%','" + reach + "','%') or " +
                    " t1.wechat_number like CONCAT('%','" + reach + "','%') or t1.szm like CONCAT('%','" + reach + "','%'))";
        }
        if (StringUtils.isNotBlank(doctor)) {
            contitionInfo += " and t.doctor ='" + doctor + "'";
        } else {
            String sql2 = "select b.id as roleid from user a left join role b on a.roleId=b.id where a.account='" + ShiroKit.getUser().getAccount() + "' limit 1";
            User user = sqlMapper.selectOne(sql2, User.class);
            if (user != null) {
                if ("1".equals(user.getRoleid()) || "1,".equals(user.getRoleid().substring(0, 2))) {
                    contitionInfo += " ";
                } else {
                    contitionInfo += " and t.doctor = '" + ShiroKit.getUser().getAccount() + "' ";
                }
            }
        }
        String sql = "select sum(serviceActualPayS) as totalPays from (" +
                "SELECT sum(t.service_actual_pay)+sum(t.deduction) as serviceActualPayS FROM doctor_change_price t LEFT JOIN " + ShiroKit.getUser().getCustomer_info() + " " +
                "t1 on t.customer_id=t1.id  where 1=1 " + contitionInfo + " GROUP BY t.reservations_id ) ts limit 1";
        DoctorChangePriceInfo info = sqlMapper.selectOne(sql, DoctorChangePriceInfo.class);
        return info;
    }

    /**
     * 医生分诊业绩统计
     */
    @RequestMapping(value = "/totalAccountFen", method = RequestMethod.GET)
    @ResponseBody
    public DoctorChangePriceInfo totalAccountFen(String param1, String param2, String param3, String param4, String treatmentUnit, String fieldTc, String doctor, String reach) throws Exception {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        String contitionInfo = "";
        if (StringUtils.isNotBlank(param1)) {
            contitionInfo += " and t.get_time >='" + param1 + "'";
        }
        if (StringUtils.isNotBlank(param2)) {
            contitionInfo += "and t.get_time <='" + param2 + "'";
        }
        if (StringUtils.isNotBlank(fieldTc)) {
            contitionInfo += " and t1.field_tc ='" + fieldTc + "'";
        }
        if (StringUtils.isNotBlank(treatmentUnit)) {
            contitionInfo += " and t1.treatment_unit ='" + treatmentUnit + "'";
        }
        if (StringUtils.isNotBlank(param4)) {
            contitionInfo += " and t1.appointment_pay_service ='" + param4 + "'";
        }
        if (StringUtils.isNotBlank(param3)) {
            contitionInfo += " and t1.arrival_store ='" + param3 + "'";
        }
        if (StringUtils.isNotBlank(reach)) {
            contitionInfo += " and (t1.customer_name like CONCAT('%','" + reach + "','%') or t1.customer_phone like CONCAT('%','" + reach + "','%') or " +
                    " t1.wechat_number like CONCAT('%','" + reach + "','%') or t1.szm like CONCAT('%','" + reach + "','%'))";
        }
        if (StringUtils.isNotBlank(doctor)) {
            contitionInfo += " and t.doctor ='" + doctor + "'";
        }
        String sql = "select sum(service_actual_pay)+sum(deduction_amount)+sum(deposit_amount) as totalfoldingPayS from (SELECT t.id2,t.service_actual_pay," +
                "if(c.charge_bill_is_docAchievement = 1,t.deduction_amount,0) as deduction_amount, if(c.charge_bill_is_docAchievement,t.deposit_amount,0) as deposit_amount  " +
                "FROM " + ShiroKit.getUser().getTriage_performance() + " t LEFT JOIN " + ShiroKit.getUser().getCustomer_info() + "  t1 on t.customer_id=t1.id LEFT JOIN checkout_method_info c ON c.id = t.deduction_type " +
                "where 1=1 and t.deal_status='已结账' " + contitionInfo + ") ts limit 1";
        DoctorChangePriceInfo info = sqlMapper.selectOne(sql, DoctorChangePriceInfo.class);
        return info;
    }

    /**
     * 统计查询
     */
    @RequestMapping(value = "/total", method = RequestMethod.GET)
    @ResponseBody
    public List<ConsultantInfo> change(String param1, String customerAgeEnd, HttpServletResponse response,
                                       String customerSex, String customerAgeStart, String doctor) throws Exception {
        String contitionInfo = "";
        if (StringUtils.isNotBlank(param1)) {
            contitionInfo += " and DATE_FORMAT(t.arrival_time, '%Y-%m-%d') = '" + param1 + "' ";
        }
        if (StringUtils.isNotBlank(customerSex)) {
            contitionInfo += " and t.customer_sex= '" + customerSex + "' ";
        }
        if (StringUtils.isNotBlank(doctor)) {
            contitionInfo += " and t.doctor= '" + doctor + "' ";
        }
        if (StringUtils.isNotBlank(customerAgeStart)) {
            contitionInfo += " and t.customer_age >= '" + customerAgeStart + "'  ";
        }
        if (StringUtils.isNotBlank(customerAgeEnd)) {
            contitionInfo += " and t.customer_age <= '" + customerAgeEnd + "' ";
        }
        String sql = "select count(1) as countNum from (select t.id from  " + ShiroKit.getUser().getCustomer_info() + " t " +
                " where t.add_status = 1 " + contitionInfo + " group by t.id) a" +
                " union all select count(1) as countNum from (select t.id from " + ShiroKit.getUser().getCustomer_info() + " t " +
                " where t.is_status = 1  " + contitionInfo + " group by t.id) a" +
                " union all select count(1) as countNum from (select t.id from " + ShiroKit.getUser().getCustomer_info() + " t " +
                " where t.visit_status ='1' " + contitionInfo + " group by t.reservations_id) a;";
        List<ConsultantInfo> tongJiInfoList1 = sqlMapper.selectList(sql, ConsultantInfo.class);
        return tongJiInfoList1;
    }

    @RequestMapping(value = "/to_addjz")
    public String to_addjz(Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        return PREFIX + "addjz.html";
    }

    @RequestMapping(value = "/to_addsj")
    public String to_addsj(Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        return PREFIX + "addsj.html";
    }

    @RequestMapping(value = "/to_addsf")
    public String to_addsf(Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        return PREFIX + "addsf.html";
    }

    @RequestMapping(value = "/to_addjg")
    public String to_addjg(Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        return PREFIX + "addjg.html";
    }

    @RequestMapping(value = "/zai_zhen/{ids}")
    public String zai_zhen(@PathVariable String ids, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        String customerId = ids.split(",")[0];
        String reservationsId = ids.split(",")[1];
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        if (ToolUtil.isEmpty(customerId)) {
            return "/doNoClose.html";
        }
        if (ToolUtil.isEmpty(reservationsId)) {
            return "/doNoClose.html";
        }
        if (ShiroKit.getUser().getDoctorInfoList() == null) {
            String doctorListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + ShiroKit.getUser().getAbbreviation() + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            List<DoctorInfo> doctorInfoList=sqlMapper.selectList(doctorListSql,DoctorInfo.class);
            ShiroKit.getUser().setDoctorInfoList(doctorInfoList);
        }
        model.addAttribute("doctorList", ShiroKit.getUser().getDoctorInfoList());
        model.addAttribute("referralerPerson", ShiroKit.getUser().getAccount()); //转诊人
        model.addAttribute("customerId", customerId);
        model.addAttribute("reservationsId", reservationsId);
        return PREFIX + "zaizhen.html";
    }

    @RequestMapping(value = "/addsf", method = RequestMethod.POST)
    @ResponseBody
    public int addsf(String remarks, String title, Model model) {
        String sql = "insert into follow_template (title,remarks,user) value ('" + title + "','" + remarks + "','" + ShiroKit.getUser().getAccount() + "')";
        return sqlMapper.insert(sql);
    }

    @RequestMapping(value = "/addjg", method = RequestMethod.POST)
    @ResponseBody
    public int addjg(String remarks, String title, Model model) {
        String sql = "insert into follow_results_template (title,remarks,user) value ('" + title + "','" + remarks + "','" + ShiroKit.getUser().getAccount() + "')";
        return sqlMapper.insert(sql);
    }

    @RequestMapping(value = "/addjz", method = RequestMethod.POST)
    @ResponseBody
    public int addjz(String remarks, String title, Model model) {
        String sql = "insert into orthodontic_template (title,remarks,user) value ('" + title + "','" + remarks + "','" + ShiroKit.getUser().getAccount() + "')";
        return sqlMapper.insert(sql);
    }

    @RequestMapping(value = "/addsj", method = RequestMethod.POST)
    @ResponseBody
    public int addsj(String remarks, String title, Model model) {
        String sql = "insert into design_scheme (title,remarks,user) value ('" + title + "','" + remarks + "','" + ShiroKit.getUser().getAccount() + "')";
        return sqlMapper.insert(sql);
    }

    /**
     * 再诊人  提交
     */
    @RequestMapping(value = "/zaizhen", method = RequestMethod.POST)
    @ResponseBody
    public int zaizhen(String zaiRemarks, String zaiPeople, String customerId, Model model) {
        String sql = "update " + ShiroKit.getUser().getCustomer_info() + " a set a.zai_people='" + zaiPeople + "'," +
                "a.zai_remarks='" + zaiRemarks + "',a.zai_time='" + DateTimeKit.now() + "' where id='" + customerId + "'";
        return sqlMapper.update(sql);
    }

    @RequestMapping(value = "/getSfList", method = RequestMethod.POST)
    @ResponseBody
    public List<SfInfo> getSfList() {
        List<SfInfo> list = service.getSfList();
        return list;
    }

    @RequestMapping(value = "/getJzList", method = RequestMethod.POST)
    @ResponseBody
    public List<SfInfo> getJzList() {
        List<SfInfo> list = service.getJzList();
        return list;
    }

    @RequestMapping(value = "/getSjList", method = RequestMethod.POST)
    @ResponseBody
    public List<SfInfo> getSjList() {
        List<SfInfo> list = service.getSjList();
        return list;
    }

    @RequestMapping(value = "/getJgList", method = RequestMethod.POST)
    @ResponseBody
    public List<JgInfo> getJgList() {
        List<JgInfo> list = service.getJgList();
        return list;
    }

    @RequestMapping(value = "/getSfById", method = RequestMethod.POST)
    @ResponseBody
    public SfInfo getSfById(String id, Model model) {
        SfInfo info = service.getSfById(id);
        return info;
    }

    @RequestMapping(value = "/getJzById", method = RequestMethod.POST)
    @ResponseBody
    public SfInfo getJzById(String id, Model model) {
        SfInfo info = service.getJzById(id);
        return info;
    }

    @RequestMapping(value = "/getSjById", method = RequestMethod.POST)
    @ResponseBody
    public SfInfo getSjById(String id, Model model) {
        SfInfo info = service.getSjById(id);
        return info;
    }

    @RequestMapping(value = "/getJgById", method = RequestMethod.POST)
    @ResponseBody
    public SfInfo getJgById(String id, Model model) {
        SfInfo info = service.getJgById(id);
        return info;
    }

    /**
     * 跳转到修改病例界面,前端传病例表ID
     */
    @RequestMapping(value = "/update/{cri}")
    public String update(@PathVariable String cri, Model model) throws Exception {
        String id = cri.split(",")[0];
        String customerId = cri.split(",")[1];
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        String sql = "select * from case_info t1 where t1.id='" + id + "' limit 1";
        CaseInfo caseInfo = sqlMapper.selectOne(sql, CaseInfo.class);//先查询病例主表单个实体
        String sql1 = "select * from tooth_site t1 where t1.case_id='" + id + "' order by id";
        List<ToothSite> toothSiteList = sqlMapper.selectList(sql1, ToothSite.class);//然后查询牙位集合,把每种检测项的多个牙位装入到对应的牙位集合里面去
        for (ToothSite toothSite : toothSiteList) {//根据对应的牙位类型,给病例实体的对应牙位属性赋值,把每组多个牙位信息通过&&拼接成一个字符串属性传到前端
            if (toothSite.getYaType().equals("1")) {
                caseInfo.getToothSite1List().add(toothSite);
            }
            if (toothSite.getYaType().equals("2")) {
                caseInfo.getToothSite2List().add(toothSite);
            }
            if (toothSite.getYaType().equals("3")) {
                caseInfo.getToothSite3List().add(toothSite);
            }
            if (toothSite.getYaType().equals("4")) {
                caseInfo.getToothSite4List().add(toothSite);
            }
            if (toothSite.getYaType().equals("5")) {
                caseInfo.getToothSite5List().add(toothSite);
            }
        }
        if (ShiroKit.getUser().getDoctorInfoList() == null) {
            String doctorListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + ShiroKit.getUser().getAbbreviation() + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            List<DoctorInfo> doctorInfoList=sqlMapper.selectList(doctorListSql,DoctorInfo.class);
            ShiroKit.getUser().setDoctorInfoList(doctorInfoList);
        }
        model.addAttribute("list", ShiroKit.getUser().getDoctorInfoList());
        ConsultantInfo consultantInfo = consultantService.selectOneById(customerId);
        String sql2 = "select * from pay_service_grade_info";
        List<PayServicedInfo> payServiceInfo = sqlMapper.selectList(sql2, PayServicedInfo.class);
        model.addAttribute("payServiceInfo", payServiceInfo);
        model.addAttribute("consultantInfo", consultantInfo);
        model.addAttribute("caseInfo", caseInfo);
        model.addAttribute("customerId", customerId);
        return PREFIX + "update_record.html";
    }

    /**
     * 保存修改病历
     */
    @RequestMapping(value = "/update_record")
    @ResponseBody
    public int updateRecord(@Valid CaseInfo info, BindingResult result) throws Exception {
        if (result.hasErrors()) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        try {
            info.setStatus(2);
            service.update(info);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 1;
    }

    /**
     * 提交修改病历
     */
    @RequestMapping(value = "/update_records")
    @ResponseBody
    public int updateRecords(@Valid CaseInfo info, BindingResult result) throws Exception {
        if (result.hasErrors()) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        try {
            info.setStatus(1);
            service.update(info);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 1;
    }

    /**
     * 提交修改病历
     */
    @RequestMapping(value = "/update_finsh")
    @ResponseBody
    public int updateFinsh(@Valid CaseInfo info, BindingResult result) throws Exception {
        if (result.hasErrors()) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        try {
            info.setStatus(1);
            service.updateFinsh(info);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 1;
    }

    /**
     * 查看病例详情
     *
     * @param id    病例ID
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/case_details/{id}")
    public String selectCaseInfoDetail(@PathVariable String id, Model model) throws Exception {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (ToolUtil.isEmpty(id)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        String sql = "select * from case_info t1 where t1.id='" + id + "' limit 1";
        CaseInfo caseInfo = sqlMapper.selectOne(sql, CaseInfo.class);//先查询病例主表单个实体
        caseInfo.setFinnallyTime(caseInfo.getFinnallyTime().substring(0, 19));
        String sql1 = "select * from tooth_site t1 where t1.case_id='" + id + "' order by id";
        List<ToothSite> toothSiteList = sqlMapper.selectList(sql1, ToothSite.class);//然后查询牙位集合,把每种检测项的多个牙位装入到对应的牙位集合里面去
        for (ToothSite toothSite : toothSiteList) {//根据对应的牙位类型,给病例实体的对应牙位属性赋值,把每组多个牙位信息通过&&拼接成一个字符串属性传到前端
            if (toothSite.getYaType().equals("1")) {
                caseInfo.getToothSite1List().add(toothSite);
            }
            if (toothSite.getYaType().equals("2")) {
                caseInfo.getToothSite2List().add(toothSite);
            }
            if (toothSite.getYaType().equals("3")) {
                caseInfo.getToothSite3List().add(toothSite);
            }
            if (toothSite.getYaType().equals("4")) {
                caseInfo.getToothSite4List().add(toothSite);
            }
            if (toothSite.getYaType().equals("5")) {
                caseInfo.getToothSite5List().add(toothSite);
            }
        }
        if (ShiroKit.getUser().getDoctorInfoList() == null) {
            String doctorListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + ShiroKit.getUser().getAbbreviation() + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            List<DoctorInfo> doctorInfoList=sqlMapper.selectList(doctorListSql,DoctorInfo.class);
            ShiroKit.getUser().setDoctorInfoList(doctorInfoList);
        }
        model.addAttribute("list", ShiroKit.getUser().getDoctorInfoList());
        model.addAttribute("caseInfo", caseInfo);
        return PREFIX + "case_details.html";
    }

    /**
     * 除单个病例信息
     */
    @RequestMapping(value = "/deleteCase", method = RequestMethod.POST)
    @ResponseBody
    public int deleteCaseInfo(String id, String customerId) throws Exception {
        String sql1 = "delete from tooth_site where case_id = '" + id + "'";
        sqlMapper.delete(sql1);//删除病例对应的牙位信息
        String sql = "delete from case_info where id = '" + id + "'";
        String selectSql2 = "select * from " + ShiroKit.getUser().getCustomer_info() + " t where id='" + customerId + "' limit 1";
        CustomerInfo customerInfo = sqlMapper.selectOne(selectSql2, CustomerInfo.class);
        String inertsq1 = "INSERT INTO `case_info_log` (createtime,reservations_id,case_id,single_person,logtype, `userid`, `customer_status`, `customer_name`,`customer_phone`," +
                " `succeed`,outpatient_name ,`message`,customer_id) VALUES " +
                " ('" + DateTimeKit.now() + "','" + customerInfo.getReservationsId() + "','" + id + "','" + ShiroKit.getUser().getAccount() + "','删除病历','" + ShiroKit.getUser().getId() + "','" + customerInfo.getCustomerStatus() + "', '"
                + customerInfo.getCustomerName() + "', '" + customerInfo.getCustomerPhone() + "','成功','" + ShiroKit.getUser().getOutpatientName() +
                "','" + ShiroKit.getUser().getAccount() + " 把 " + customerInfo.getCustomerName() + " 的病历在:" + DateTimeKit.now() + "进行删除','" + customerId + "');";
        sqlMapper.insert(inertsq1);//插入删除日志
        return sqlMapper.delete(sql);//删除病例表对应ID的病例信息
    }

    /**
     * 除单个病例信息
     */
    @RequestMapping(value = "/deleteCases", method = RequestMethod.POST)
    @ResponseBody
    public int deleteCases(String caseId) {
        String sql1 = "delete from tooth_site where case_id = '" + caseId + "'";
        sqlMapper.delete(sql1);//删除病例对应的牙位信息
        String sql = "delete from case_info where id = '" + caseId + "'";
        return sqlMapper.delete(sql);//删除病例表对应ID的病例信息
    }

    /**
     * 跳转到医生划价界面reservationsId
     *
     * @return
     */
    @RequestMapping(value = "/change_price/{reservationsId}")
    public String changePrice(@PathVariable String reservationsId, Model model) throws Exception {
        if (ToolUtil.isEmpty(reservationsId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        model.addAttribute("reservationsId", reservationsId);
        return PREFIX + "change_price.html";
    }

    /**
     * 医生划价
     *
     * @return
     */
    @RequestMapping(value = "/change_price1/{customerId}")
    public String changePrice1(@PathVariable String customerId, Model model) throws Exception {
        if (ToolUtil.isEmpty(customerId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        CustomerInfo customerInfo = customerService.selectOneById(customerId);
        String sqll = "SELECT sum(service_actual_pay) AS serviceActualPay,sum(arrears) AS arrears FROM  " +
                "" + ShiroKit.getUser().getDeal_info() + " a  WHERE a.reservations_id = '" + customerInfo.getReservationsId() + "' AND a.doctor = '" + ShiroKit.getUser().getAccount() + "' " +
                "GROUP BY a.reservations_id limit 1";
        PayServicedInfo payServiceInfo = sqlMapper.selectOne(sqll, PayServicedInfo.class);
        //成交记录
        String sql = "select t1.id as id,t1.customer_id as customerId ,t1.reservations_id as reservationsId ,t1.outpatient_name as outpatientName , t1.deal_status  as dealStatus, t1.tc_name as tcName ,t1.pay_service_num as payServiceNum ," +
                " t1.service_actual_pay as serviceActualPay ,left(t1.operation_time,19) as operationTime," +
                "sum(t1.service_actual_pay) as totleServiceActualPay," +
                "(select sum(folding_pay) from " + ShiroKit.getUser().getDeal_info() + " a where a.operation_time=t1.operation_time and a.operation_time=a.get_time) as totleFoldingPay," +
                "sum(t1.arrears) as totleArrears,group_concat(distinct t1.remarks) as remarks," +
                " t1.folding_pay as foldingPay,t1.pay_service as payService," +
                "t2.id as payServiceId,t2.department as department,t2.first_level_project as firstLevelProject,t1.arrears as arrears," +
                "group_concat(distinct t2.pay_service_name) as payServiceName, t2.pay_service_price_one as payServicePriceOne, t2.pay_service_price_two as payServicePriceTwo," +
                "left(t1.get_time,19) as getTime ," +
                " group_concat(distinct t1.doctor) as doctor" +
                " from " + ShiroKit.getUser().getDeal_info() + " t1 left join " + ShiroKit.getUser().getPay_service_info() + " t2 on t1.pay_service_id=t2.id " +
                " where t1.reservations_id='" + customerInfo.getReservationsId() + "' and pay_service_id is not null and t1.doctor='" + ShiroKit.getUser().getAccount() + "' and t1.deal_status='已结账' " +
                " group by  operationTime order by operationTime desc";
        List<PayServicedInfo> payServiceInfoList = sqlMapper.selectList(sql, PayServicedInfo.class);
        //患者详情
        String sql1 = " select " +
                "  (CASE a.customer_sex " +
                "  WHEN 1 THEN " +
                "  '男' " +
                "  WHEN 2 THEN " +
                "  '女' " +
                "  ELSE " +
                "  '未知' " +
                "  END " +
                " ) as sex ,a.* from " + ShiroKit.getUser().getCustomer_info() + " a where id='" + customerId + "' limit 1";
        ConsultantInfo consultantInfo = sqlMapper.selectOne(sql1, ConsultantInfo.class);
        String getTime = "";
        for (PayServicedInfo info : payServiceInfoList) {
            if (info != null) {
                if (info.getOperationTime() != "" && info.getOperationTime() != null) {
                    info.setOperationTimeOne(info.getOperationTime().substring(0, 10));
                    info.setOperationTimeTwo(info.getOperationTime().substring(11, info.getOperationTime().length()));
                }
                getTime = info.getGetTime();
            }
        }
        model.addAttribute("payServiceInfoList", payServiceInfoList);
        model.addAttribute("reservationsId", customerInfo.getReservationsId());
        model.addAttribute("customerInfo", customerInfo);
        model.addAttribute("consultantInfo", consultantInfo);
        model.addAttribute("payServiceInfo", payServiceInfo);
        model.addAttribute("getTime", getTime);
        model.addAttribute("userName", ShiroKit.getUser().getAccount());
        model.addAttribute("customerId", customerId);
        return PREFIX + "change_price1.html";
    }

    /**
     * 点击一键划价 预览
     *
     * @param id
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/hu_price/{id}")
    public String hu_price(@PathVariable String id, Model model) throws Exception {
        if (ToolUtil.isEmpty(id)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        CustomerInfo customerInfo = customerService.selectOneById(id);
        String sqll = "SELECT sum(service_actual_pay) AS serviceActualPay,sum(arrears) AS arrears,a.doctor as doctor FROM  " +
                "" + ShiroKit.getUser().getDeal_info() + " a  WHERE a.reservations_id='" + customerInfo.getReservationsId() + "' " +
                " AND a.doctor = '" + ShiroKit.getUser().getAccount() + "' GROUP BY a.id limit 1";
        PayServicedInfo payServiceInfo = sqlMapper.selectOne(sqll, PayServicedInfo.class);
        String sql22 = "select sum(service_actual_pay) as serviceActualPay from doctor_change_price a where a.reservations_id='" + customerInfo.getReservationsId() + "' group by a.reservations_id";
        DoctorChangePriceInfo changePriceInfo = sqlMapper.selectOne(sql22, DoctorChangePriceInfo.class);
        //成交记录
        String sql = "select t1.id as id,t1.customer_id as customerId , t1.reservations_id as reservationsId ,t1.outpatient_name as outpatientName , t1.deal_status  as dealStatus, t1.tc_name as tcName ,t1.pay_service_num as payServiceNum ," +
                " t1.service_actual_pay as serviceActualPay ,left(t1.operation_time,19) as operationTime," +
                "sum(t1.service_actual_pay) as totleServiceActualPay,sum(t1.deduction_amount) as totlDeductionAmount," +
                "(select sum(folding_pay) from " + ShiroKit.getUser().getDeal_info() + " a where a.operation_time=t1.operation_time and a.operation_time=a.get_time) as totleFoldingPay," +
                "sum(t1.arrears) as totleArrears,group_concat(distinct t1.remarks) as remarks," +
                " t1.folding_pay as foldingPay,t1.pay_service as payService," +
                "t2.id as payServiceId,t2.department as department,t2.first_level_project as firstLevelProject,t1.arrears as arrears," +
                "group_concat(distinct t2.pay_service_name) as payServiceName, t2.pay_service_price_one as payServicePriceOne, t2.pay_service_price_two as payServicePriceTwo," +
                "left(t1.get_time,19) as getTime ," +
                " group_concat(distinct t1.doctor) as doctor" +
                " from " + ShiroKit.getUser().getDeal_info() + " t1 left join " + ShiroKit.getUser().getPay_service_info() + " t2 on t1.pay_service_id=t2.id " +
                " where t1.reservations_id='" + customerInfo.getReservationsId() + "' and pay_service_id is not null and t1.doctor='" + ShiroKit.getUser().getAccount() + "' and t1.deal_status='已结账' " +
                " group by  operationTime order by operationTime desc";
        List<PayServicedInfo> payServiceInfoList = sqlMapper.selectList(sql, PayServicedInfo.class);
        //患者详情
        String sql1 = " select " +
                "  (CASE a.customer_sex " +
                "  WHEN 1 THEN " +
                "  '男' " +
                "  WHEN 2 THEN " +
                "  '女' " +
                "  ELSE " +
                "  '未知' " +
                "  END " +
                " ) as sex ,a.* from " + ShiroKit.getUser().getCustomer_info() + " a where id='" + id + "'";
        ConsultantInfo consultantInfo = sqlMapper.selectOne(sql1, ConsultantInfo.class);
        String getTime = "";
        for (PayServicedInfo info : payServiceInfoList) {
            if (info != null) {
                if (info.getOperationTime() != "" && info.getOperationTime() != null) {
                    info.setOperationTimeOne(info.getOperationTime().substring(0, 10));
                    info.setOperationTimeTwo(info.getOperationTime().substring(11, info.getOperationTime().length()));
                }
                getTime = info.getGetTime();
            }
        }
        model.addAttribute("payServiceInfoList", payServiceInfoList);
        model.addAttribute("reservationsId", customerInfo.getReservationsId());
        model.addAttribute("customerId", id);
        model.addAttribute("customerInfo", customerInfo);
        model.addAttribute("payServiceInfo", payServiceInfo);
        model.addAttribute("changePriceInfo", changePriceInfo);
        model.addAttribute("getTime", getTime);
        model.addAttribute("consultantInfo", consultantInfo);
        model.addAttribute("userName", ShiroKit.getUser().getAccount());
        return PREFIX + "change_price_info.html";
    }

    /**
     * 单次划价
     *
     * @param id
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/huajia/{id}")
    public String huaJia(@PathVariable String id, Model model) throws Exception {
        if (ToolUtil.isEmpty(id)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        String sql1 = "select * from " + ShiroKit.getUser().getDeal_info() + " where id='" + id + "'";
        PayServicedInfo payServiceInfo = sqlMapper.selectOne(sql1, PayServicedInfo.class);
        model.addAttribute("id", id);
        model.addAttribute("payServiceInfo", payServiceInfo);
        return PREFIX + "change_price_info1.html";
    }

    /**
     * 该客户所有的项目列表,前台AJAX POST 请求要传递三个参数
     *
     * @return reservationsId, customerId, operationTime
     */
    @RequestMapping(value = "/changePriceTable/{reservationsId}")
    @ResponseBody
    public List<PayServicedInfo> changePriceTable(@PathVariable String reservationsId) throws Exception {
        String sql = "select t1.id as id,t1.customer_id as customerId ,t1.reservations_id as reservationsId ," +
                "t1.outpatient_name as outpatientName , t1.deal_status  as dealStatus, t1.tc_name as tcName ," +
                "t1.pay_service_num as payServiceNum ,t1.service_actual_pay as serviceActualPay ," +
                "left(t1.operation_time,19) as operationTime,t1.remarks as remarks,t1.check_status as checkStatus," +
                " t1.folding_pay as foldingPay,t1.doctor as doctor ,t1.left_up as leftUp ," +
                "t1.left_down as leftDown ,t1.right_up as rightUp ,t1.right_down as rightDown ,t1.pay_service as payService," +
                "t2.id as payServiceId,t2.department as department,t2.first_level_project as firstLevelProject,t1.arrears as arrears," +
                "t2.pay_service_name as payServiceName ,t2.pay_service_price_one as payServicePriceOne, t2.pay_service_price_two as payServicePriceTwo," +
                "t3.customer_name as customerName ," +
                "t3.medical_record_number as medicalRecordNumber,t3.customer_status as customerStatus ,t3.customer_sex as customerSex ,t3.customer_phone as customerPhone,t3.customer_age as customerAge, " +
                " ( " +
                " CASE t3.customer_sex " +
                " WHEN 1 THEN " +
                "     '男' " +
                " WHEN 2 THEN " +
                "     '女' " +
                " ELSE " +
                "     '未知' " +
                " END " +
                "    ) as sex  ,t3.arrival_store as arrivalStore," +
                "t3.field_tc as fieldTc from " + ShiroKit.getUser().getDeal_info() + " t1 left join " + ShiroKit.getUser().getPay_service_info() + " t2 on t1.pay_service_id=t2.id left join " + ShiroKit.getUser().getCustomer_info() + " t3 on t1.customer_id=t3.id" +
                " where t1.reservations_Id = '" + reservationsId + "' and t1.deal_status='已结账' and t1.doctor='" + ShiroKit.getUser().getAccount() + "' group by t1.operation_time,t1.reservations_id,t1.pay_service_id";
        List<PayServicedInfo> payServiceInfoList = sqlMapper.selectList(sql, PayServicedInfo.class);
        return payServiceInfoList;
    }

    /**
     * 划价改变项目的状态,根据当前开单的ID
     *
     * @return
     */
    @RequestMapping(value = "/hua_price/{id}")
    @ResponseBody
    public int updateStatus(@PathVariable String id) {
        String sql = "update " + ShiroKit.getUser().getDeal_info() + "  set check_status ='1' where id2 = '" + id + "'";
        return sqlMapper.update(sql);
    }

    /**
     * 划价记录 修改插入
     *
     * @return
     */
    @RequestMapping(value = "/update_price")
    @ResponseBody
    public int updatePrice(String serviceActualPay, String deductionAmount, String createTime) {
        String sql = "update doctor_change_price a  set a.service_actual_pay='" + serviceActualPay + "',a.deduction='" + deductionAmount + "'," +
                "a.update_people='" + ShiroKit.getUser().getAccount() + "',update_time='" + DateTimeKit.now() + "' where create_time = '" + createTime + "'";
        return sqlMapper.update(sql);
    }

    /**
     * 转诊  修改医生
     *
     * @return
     */
    @RequestMapping(value = "/updateDoctor", method = RequestMethod.POST)
    @ResponseBody
    public int updateDoctor(String doctor, String customerId, String remarks, String time, String optType) {//optType 0:不强制执行  1:强制执行
        String sql1 = "select id from user where account ='" + doctor + "' limit 0,1";
        User user = sqlMapper.selectOne(sql1, User.class);
        String sql2 = "select status from doctor_scheduling where doctor_id='" + user.getId() + "' and the_date='" + time + "' and outpatient_name='" + ShiroKit.getUser().getOutpatientName() + "'";
        DoctorSchedulingInfo info = sqlMapper.selectOne(sql2, DoctorSchedulingInfo.class);
        if (info != null) {
            if (info.getStatus().intValue() == 1 || optType.equals("1")) {//如果当前医生有排班或者需要强制执行转正,执行转诊SQL
                String sql = "update " + ShiroKit.getUser().getCustomer_info() + " a  set a.doctor='" + doctor + "',a.remarks='" + remarks + "',a.transfer_status='1' where id = '" + customerId + "'";
                return sqlMapper.update(sql);//update 执行后返回的是操作影响的行数,所有值肯定是大于或者等于0
            } else { //如果当前医生没有排班,就返回-2
                return -2;
            }
        } else { //如果为空,说明排班没有冲突
            String sql = "update " + ShiroKit.getUser().getCustomer_info() + " a  set a.doctor='" + doctor + "',a.remarks='" + remarks + "',a.transfer_status='1' where id = '" + customerId + "'";
            return sqlMapper.update(sql);
        }
    }

    /**
     * 转诊
     *
     * @return
     */
    @RequestMapping(value = "/referralerPerson", method = RequestMethod.POST)
    @ResponseBody
    public int referralerPerson(String referralerPersoned, String customerId, String remarks, String referralerPerson) {
        String updateSql = "update " + ShiroKit.getUser().getCustomer_info() + " t set t.referraler_person='" + referralerPerson + "'," +
                " t.referraler_personed='" + referralerPersoned + "',t.referraler_time='" + DateTimeKit.now() + "'," +
                " t.is_referraler=1,t.referraler_remarks ='" + remarks + "' where id='" + customerId + "' ";
        return sqlMapper.update(updateSql);
    }

    /**
     * 划价记录  删除
     *
     * @return
     */
    @RequestMapping(value = "/delete_price")
    @ResponseBody
    public int deletePrice(String createTime) {
        String sql = "delete from  doctor_change_price  where create_time = '" + createTime + "'";
        return sqlMapper.delete(sql);
    }

    /**
     * 医生划价 插入医生业绩表
     */
    @RequestMapping(value = "/insert_price")
    @ResponseBody
    public int changePrice(String id2, String customerId, String payServiceName, String remarks, Double accountArrears, Double serviceActualPay, Double deductionAmount, Integer payServiceNum) {
        String sql = "select reservations_id from " + ShiroKit.getUser().getDeal_info() + " where id2='" + id2 + "' limit 0,1 ";
        PayServicedInfo info = sqlMapper.selectOne(sql, PayServicedInfo.class);
        String insertSql2 = "insert into doctor_change_price (id2,doctor,customer_id,reservations_id,pay_service_name,service_actual_pay,arrears,number,deduction,remarks,create_time,create_people)" +
                " VALUES('" + id2 + "','" + ShiroKit.getUser().getAccount() + "','" + customerId + "','" + info.getReservationsId() + "','" + payServiceName + "','" + serviceActualPay + "','" + accountArrears + "','" + payServiceNum + "','" + deductionAmount + "'," +
                "'" + remarks + "','" + DateTimeKit.now() + "','" + ShiroKit.getUser().getAccount() + "')";
        sqlMapper.insert(insertSql2);
        String sqlUpdate = "update " + ShiroKit.getUser().getCustomer_info() + " t set t.deduct_status='1' where id='" + customerId + "' ";
        sqlMapper.update(sqlUpdate);
        String selectSql = "select sum(service_actual_pay)+ sum(deduction) as totalPay,reservations_id as reservationsId from doctor_change_price where id2='" + id2 + "' group by reservations_id";
        DoctorChangePriceInfo selectInfo = sqlMapper.selectOne(selectSql, DoctorChangePriceInfo.class);
        BigDecimal data1 = new BigDecimal(selectInfo.getTotalPay());
        String selectSql1 = "select folding_pay from " + ShiroKit.getUser().getDeal_info() + " where reservations_id='" + info.getReservationsId() + "' and id2='" + id2 + "' group by reservations_id";
        PayServicedInfo selectInfo1 = sqlMapper.selectOne(selectSql1, PayServicedInfo.class);
        BigDecimal data2 = new BigDecimal(selectInfo1.getFoldingPay());
        if (data1.compareTo(data2) == 0) {
            String updateStatus = "update " + ShiroKit.getUser().getDeal_info() + " a set a.execute_status='1' where id2='" + id2 + "' ";
            return sqlMapper.update(updateStatus);
        } else {
            String updateStatus = "update " + ShiroKit.getUser().getDeal_info() + " a set a.execute_status='0' where id2='" + id2 + "' ";
            return sqlMapper.update(updateStatus);
        }
    }

    /**
     * 医生划价记录
     */
    @RequestMapping(value = "/getPriceInfo")
    @ResponseBody
    public List<DoctorChangePriceInfo> getPriceInfo(String id2) {
        String sql1 = "select t.id,t.id2 as id2,doctor as doctor,t.pay_service_name as payServiceName ,t.service_actual_pay as serviceActualPay ," +
                "t.deduction as deduction ,left(t.create_time,19) as createTime from doctor_change_price t where t.status='1' and t.id2='" + id2 + "'";
        List<DoctorChangePriceInfo> infoList = sqlMapper.selectList(sql1, DoctorChangePriceInfo.class);
        return infoList;
    }

    /**
     * 医生开始治疗修改患者状态
     *
     * @param customerId
     * @return
     */
    @RequestMapping(value = "/startTreatment", method = RequestMethod.POST)
    @ResponseBody
    public int startTreatment(String customerId) {

        String selsql = "select id, (case a.arrival_status when (1 or 9) then '预约' when 2 then '到店' when 3 then '就诊中' " +
                "when 4 then '完成治疗' when 5 then '离开' when (6 or 10) then '已打电话' " +
                "when 7 then '失约' when 8 then '取消预约' else '其他' end) as arrivalStatusName,a.customer_name,a.customer_phone,a.customer_status," +
                "a.reservations_id,a.arrival_status from  " + ShiroKit.getUser().getCustomer_info() + " a where id = '" + customerId + "'";
        CustomerInfo customerInfo = sqlMapper.selectOne(selsql, CustomerInfo.class);
        if (("1").equals(customerInfo.getArrivalStatus()) || ("6").equals(customerInfo.getArrivalStatus())) { //未挂号患者医生点了接诊
            service.regresses(customerId); //先走挂号方法
        }
        String sql = "update " + ShiroKit.getUser().getCustomer_info() + "  set arrival_status ='3' where id = '" + customerId + "'";
        //插入视图改动日志 开始治疗
        String sq11 = "INSERT INTO `customer_reservations_update_log` (createtime,single_person,logtype, `userid`, `customer_status`, `customer_name`,`customer_phone`," +
                " `succeed`,outpatient_name ,`message`,customer_id) VALUES " +
                " ('" + DateTimeKit.now() + "','" + ShiroKit.getUser().getAccount() + "','修改预约','" + ShiroKit.getUser().getId() + "','" + customerInfo.getCustomerStatus() + "', '"
                + customerInfo.getCustomerName() + "', '" + customerInfo.getCustomerPhone() + "','成功','" + ShiroKit.getUser().getOutpatientName() +
                "','预约状态：" + customerInfo.getArrivalStatusName() + "->开始治疗','" + customerId + "');";
        sqlMapper.update(sql);
        webSocket.sendMessageViews("开始治疗", ShiroKit.getUser().getAbbreviation());
        return sqlMapper.insert(sq11);
    }

    //完成治疗
    @RequestMapping(value = "/completionTreatment", method = RequestMethod.POST)
    @ResponseBody
    public int completionTreatment(String customerId) {
        String sql = "update " + ShiroKit.getUser().getCustomer_info() + "  set arrival_status ='4' where id = '" + customerId + "'";
        String selsql = "select id, (case a.arrival_status when (1 or 9) then '预约' when 2 then '到店' when 3 then '就诊中' " +
                "when 4 then '完成治疗' when 5 then '离开' when (6 or 10) then '已打电话' " +
                "when 7 then '失约' when 8 then '取消预约' else '其他' end) as arrivalStatusName,a.customer_name,a.customer_phone,a.customer_status," +
                "a.reservations_id from  " + ShiroKit.getUser().getCustomer_info() + " a where id = '" + customerId + "'";
        CustomerInfo customerInfo = sqlMapper.selectOne(selsql, CustomerInfo.class);
        //插入视图改动日志 完成治疗
        String sq11 = "INSERT INTO `customer_reservations_update_log` (createtime,single_person,logtype, `userid`, `customer_status`, `customer_name`,`customer_phone`," +
                " `succeed`,outpatient_name ,`message`,customer_id) VALUES " +
                " ('" + DateTimeKit.now() + "','" + ShiroKit.getUser().getAccount() + "','修改预约','" + ShiroKit.getUser().getId() + "','" + customerInfo.getCustomerStatus() + "', '"
                + customerInfo.getCustomerName() + "', '" + customerInfo.getCustomerPhone() + "','成功','" + ShiroKit.getUser().getOutpatientName() +
                "','预约状态：" + customerInfo.getArrivalStatusName() + "->完成治疗','" + customerId + "');";
        sqlMapper.insert(sq11);
        webSocket.sendMessageViews("完成治疗", ShiroKit.getUser().getAbbreviation());
        return sqlMapper.update(sql);
    }

    //回退
    @RequestMapping(value = "/returnTo", method = RequestMethod.POST)
    @ResponseBody
    public String returnTo(String customerId, Model model) {
        String sql = "update " + ShiroKit.getUser().getCustomer_info() + " set arrival_status = arrival_status-1 where id = '" + customerId + "'";
        int a = sqlMapper.update(sql);
        String sql2 = "select id,arrival_status from " + ShiroKit.getUser().getCustomer_info() + " where id= '" + customerId + "'";
        ConsultantInfo customerInfo = sqlMapper.selectOne(sql2, ConsultantInfo.class);
        return a + "," + customerInfo.getArrivalStatus();
    }

    //患者取消预约
    @RequestMapping("/cancelAppointment/{customerId}")
    public String cancelAppointment(@PathVariable String customerId, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        String sql1 = "select * from " + ShiroKit.getUser().getCustomer_info() + " where id = '" + customerId + "' ";
        CustomerInfo info = sqlMapper.selectOne(sql1, CustomerInfo.class);
        model.addAttribute("customerInfo", info);
        return PREFIX + "doctor_cancelAppointment.html";
    }

    //患者取消预约
    @RequestMapping(value = "/cancelAppointmentok", method = RequestMethod.POST)
    @ResponseBody
    public int cancelAppointmentok(String customerId, String remarks) {
        String sql = "update " + ShiroKit.getUser().getCustomer_info() + " set arrival_status='8',status='取消预约',remarks='" + remarks + "' where id = '" + customerId + "'";
        String selsql = "select id, a.customer_name,a.customer_phone,a.reservations_id from  " + ShiroKit.getUser().getCustomer_info() + " a where id = '" + customerId + "'";
        CustomerInfo customerInfo = sqlMapper.selectOne(selsql, CustomerInfo.class);
        //插入视图改动日志 取消预约
        String sq11 = "INSERT INTO `customer_reservations_update_log` (createtime,single_person,logtype, `userid`, `customer_status`, `customer_name`,`customer_phone`," +
                " `succeed`,outpatient_name ,`message`,customer_id,remarks) VALUES " +
                " ('" + DateTimeKit.now() + "','" + ShiroKit.getUser().getAccount() + "','取消预约','" + ShiroKit.getUser().getId() + "','取消预约', '"
                + customerInfo.getCustomerName() + "', '" + customerInfo.getCustomerPhone() + "','成功','" + ShiroKit.getUser().getOutpatientName() +
                "','预约状态：预约->取消预约','" + customerId + "','" + remarks + "');";
        sqlMapper.insert(sq11);
        webSocket.sendMessageViews("取消预约", ShiroKit.getUser().getAbbreviation());
        return sqlMapper.update(sql);
    }

    /**
     * 患者到店
     *
     * @param customerId
     * @return
     */
    @RequestMapping(value = "/regresses", method = RequestMethod.POST)
    @ResponseBody
    public int regresses(String customerId) {
        return service.regresses(customerId);
    }

    /**
     * 患者离开
     *
     * @param customerId
     * @return
     */
    @RequestMapping(value = "/alreadyLeave", method = RequestMethod.POST)
    @ResponseBody
    public int alreadyLeave(String customerId) {
        String sql = "update " + ShiroKit.getUser().getCustomer_info() + "  set arrival_status ='5' where id = '" + customerId + "'";
        String selsql = "select id, (case a.arrival_status when (1 or 9) then '预约' when 2 then '到店' when 3 then '就诊中' " +
                "when 4 then '完成治疗' when 5 then '离开' when (6 or 10) then '已打电话' " +
                "when 7 then '失约' when 8 then '取消预约' else '其他' end) as arrivalStatusName,a.customer_name,a.customer_phone,a.customer_status," +
                "a.reservations_id from  " + ShiroKit.getUser().getCustomer_info() + " a where id = '" + customerId + "'";
        CustomerInfo customerInfo = sqlMapper.selectOne(selsql, CustomerInfo.class);
        //插入视图改动日志 已离开
        String sq11 = "INSERT INTO `customer_reservations_update_log` (createtime,single_person,logtype, `userid`, `customer_status`, `customer_name`,`customer_phone`," +
                " `succeed`,outpatient_name ,`message`,customer_id,reservations_id) VALUES " +
                " ('" + DateTimeKit.now() + "','" + ShiroKit.getUser().getAccount() + "','修改预约','" + ShiroKit.getUser().getId() + "','" + customerInfo.getCustomerStatus() + "', '"
                + customerInfo.getCustomerName() + "', '" + customerInfo.getCustomerPhone() + "','成功','" + ShiroKit.getUser().getOutpatientName() +
                "','预约状态：" + customerInfo.getArrivalStatusName() + "->已离开','" + customerId + "','" + customerInfo.getReservationsId() + "');";
        sqlMapper.insert(sq11);
        webSocket.sendMessageViews("已离开", ShiroKit.getUser().getAbbreviation());
        return sqlMapper.update(sql);
    }

    /**
     * 点击确认
     *
     * @param customerId
     * @return
     */
    @RequestMapping(value = "/sureAppointment", method = RequestMethod.POST)
    @ResponseBody
    public int sureAppointment(String customerId) {
        String selsql = "select * from  " + ShiroKit.getUser().getCustomer_info() + " where id = '" + customerId + "'";
        CustomerInfo customerIn = sqlMapper.selectOne(selsql, CustomerInfo.class);
        String sql = " ";
        if (("9").equals(customerIn.getArrivalStatus()) || ("10").equals(customerIn.getArrivalStatus())) {
            sql = "update " + ShiroKit.getUser().getCustomer_info() + "  set arrival_status ='10' where id = '" + customerId + "'";
        } else {
            sql = "update " + ShiroKit.getUser().getCustomer_info() + "  set arrival_status ='6' where id = '" + customerId + "'";
        }
        //插入视图改动日志 预约确定
        String sq11 = "INSERT INTO `customer_reservations_update_log` (createtime,single_person,logtype, `userid`, `customer_status`, `customer_name`,`customer_phone`," +
                " `succeed`,outpatient_name ,`message`,customer_id) VALUES " +
                " ('" + DateTimeKit.now() + "','" + ShiroKit.getUser().getAccount() + "','修改预约','" + ShiroKit.getUser().getId() + "','预约', '"
                + customerIn.getCustomerName() + "', '" + customerIn.getCustomerPhone() + "','成功','" + ShiroKit.getUser().getOutpatientName() +
                "','预约状态：预约->确定','" + customerId + "');";
        sqlMapper.insert(sq11);
        webSocket.sendMessageViews("确定", ShiroKit.getUser().getAbbreviation());
        return sqlMapper.update(sql);
    }

    /**
     * 点击取消确认
     *
     * @param customerId
     * @return
     */
    @RequestMapping(value = "/no_sureAppointment", method = RequestMethod.POST)
    @ResponseBody
    public int no_sureAppointment(String customerId) {
        String sql = "update " + ShiroKit.getUser().getCustomer_info() + "  set arrival_status ='1' where id = '" + customerId + "'";
        String selsql = "select customer_status,customer_name,Customer_phone from  " + ShiroKit.getUser().getCustomer_info() + " where id = '" + customerId + "'";
        CustomerInfo customerInfo = sqlMapper.selectOne(selsql, CustomerInfo.class);
        //插入视图改动日志 取消确定
        String sq11 = "INSERT INTO `customer_reservations_update_log` (createtime,single_person,logtype, `userid`, `customer_status`, `customer_name`,`customer_phone`," +
                " `succeed`,outpatient_name ,`message`,customer_id) VALUES " +
                " ('" + DateTimeKit.now() + "','" + ShiroKit.getUser().getAccount() + "','修改预约','" + ShiroKit.getUser().getId() + "','预约', '"
                + customerInfo.getCustomerName() + "', '" + customerInfo.getCustomerPhone() + "','成功','" + ShiroKit.getUser().getOutpatientName() +
                "','预约状态：确定->取消确定','" + customerId + "');";
        sqlMapper.insert(sq11);
        return sqlMapper.update(sql);
    }

    /**
     * 患者离开
     *
     * @param customerId
     * @return2
     */
    @RequestMapping(value = "/fallbackAction", method = RequestMethod.POST)
    @ResponseBody
    public int fallbackAction(String customerId, String arrivalStatus) {
        String selsql = "select id,a.arrival_status,(case a.arrival_status when (1 or 9) then '预约' when 2 then '到店' when 3 then '就诊中' " +
                "when 4 then '完成治疗' when 5 then '离开' when (6 or 10) then '已打电话' " +
                "when 7 then '失约' when 8 then '取消预约' else '其他' end) as arrivalStatusName,a.customer_name,a.customer_phone,a.customer_status," +
                "a.reservations_id from  " + ShiroKit.getUser().getCustomer_info() + " a where id = '" + customerId + "'";
        CustomerInfo customerInfo = sqlMapper.selectOne(selsql, CustomerInfo.class);
        if (arrivalStatus.equals("5")) {
            String sql = "update " + ShiroKit.getUser().getCustomer_info() + "  set arrival_status ='4' where id = '" + customerId + "'";
            sqlMapper.update(sql);
            //插入视图改动日志 回退
            String sq11 = "INSERT INTO `customer_reservations_update_log` (createtime,single_person,logtype, `userid`, `customer_status`, `customer_name`,`customer_phone`," +
                    " `succeed`,outpatient_name ,`message`,customer_id,reservations_id) VALUES " +
                    " ('" + DateTimeKit.now() + "','" + ShiroKit.getUser().getAccount() + "','修改预约','" + ShiroKit.getUser().getId() + "','" + customerInfo.getCustomerStatus() + "', '"
                    + customerInfo.getCustomerName() + "', '" + customerInfo.getCustomerPhone() + "','成功','" + ShiroKit.getUser().getOutpatientName() +
                    "','预约状态：离开->完成治疗','" + customerId + "','" + customerInfo.getReservationsId() + "');";
            sqlMapper.insert(sq11);
        } else if (arrivalStatus.equals("4")) {
            String sql = "update " + ShiroKit.getUser().getCustomer_info() + "  set arrival_status ='3' where id = '" + customerId + "'";
            //插入视图改动日志 回退
            String sq11 = "INSERT INTO `customer_reservations_update_log` (createtime,single_person,logtype, `userid`, `customer_status`, `customer_name`,`customer_phone`," +
                    " `succeed`,outpatient_name ,`message`,customer_id,reservations_id) VALUES " +
                    " ('" + DateTimeKit.now() + "','" + ShiroKit.getUser().getAccount() + "','修改预约','" + ShiroKit.getUser().getId() + "','" + customerInfo.getCustomerStatus() + "', '"
                    + customerInfo.getCustomerName() + "', '" + customerInfo.getCustomerPhone() + "','成功','" + ShiroKit.getUser().getOutpatientName() +
                    "','预约状态：完成治疗->就诊中','" + customerId + "','" + customerInfo.getReservationsId() + "');";
            sqlMapper.update(sql);
            sqlMapper.insert(sq11);
        } else if (arrivalStatus.equals("3")) {
            String sql = "update " + ShiroKit.getUser().getCustomer_info() + "  set arrival_status ='2' where id = '" + customerId + "'";
            //插入视图改动日志 回退
            String sq11 = "INSERT INTO `customer_reservations_update_log` (createtime,single_person,logtype, `userid`, `customer_status`, `customer_name`,`customer_phone`," +
                    " `succeed`,outpatient_name ,`message`,customer_id,reservations_id) VALUES " +
                    " ('" + DateTimeKit.now() + "','" + ShiroKit.getUser().getAccount() + "','修改预约','" + ShiroKit.getUser().getId() + "','" + customerInfo.getCustomerStatus() + "', '"
                    + customerInfo.getCustomerName() + "', '" + customerInfo.getCustomerPhone() + "','成功','" + ShiroKit.getUser().getOutpatientName() +
                    "','预约状态：就诊中->到店','" + customerId + "','" + customerInfo.getReservationsId() + "');";
            sqlMapper.update(sql);
            sqlMapper.insert(sq11);
        } else if (arrivalStatus.equals("7")) {
            String sql = "update " + ShiroKit.getUser().getCustomer_info() + "  set arrival_status ='1' where id = '" + customerId + "'";
            //插入视图改动日志 回退
            String sq11 = "INSERT INTO `customer_reservations_update_log` (createtime,single_person,logtype, `userid`, `customer_status`, `customer_name`,`customer_phone`," +
                    " `succeed`,outpatient_name ,`message`,customer_id,reservations_id) VALUES " +
                    " ('" + DateTimeKit.now() + "','" + ShiroKit.getUser().getAccount() + "','修改预约','" + ShiroKit.getUser().getId() + "','" + customerInfo.getCustomerStatus() + "', '"
                    + customerInfo.getCustomerName() + "', '" + customerInfo.getCustomerPhone() + "','成功','" + ShiroKit.getUser().getOutpatientName() +
                    "','预约状态：失约->预约','" + customerId + "','" + customerInfo.getReservationsId() + "');";
            sqlMapper.insert(sq11);
            sqlMapper.update(sql);
        } else if (arrivalStatus.equals("2")) {
            String sql = "update " + ShiroKit.getUser().getCustomer_info() + "  set arrival_status ='1',status ='预约',arrival_time=null,customer_status =null where id = '" + customerId + "'";
            //插入视图改动日志 回退
            String sq11 = "INSERT INTO `customer_reservations_update_log` (createtime,single_person,logtype, `userid`, `customer_status`, `customer_name`,`customer_phone`," +
                    " `succeed`,outpatient_name ,`message`,customer_id,reservations_id) VALUES " +
                    " ('" + DateTimeKit.now() + "','" + ShiroKit.getUser().getAccount() + "','修改预约','" + ShiroKit.getUser().getId() + "','" + customerInfo.getCustomerStatus() + "', '"
                    + customerInfo.getCustomerName() + "', '" + customerInfo.getCustomerPhone() + "','成功','" + ShiroKit.getUser().getOutpatientName() +
                    "','预约状态：到店->预约','" + customerId + "','" + customerInfo.getReservationsId() + "');";
            sqlMapper.update(sql);
            sqlMapper.insert(sq11);
            String sql2 = "select id from reservations_info where id='" + customerInfo.getReservationsId() + "' " +
                    "and left(first_visit_date,10) = '" + (DateTimeKit.now()).substring(0, 10) + "' and one_channel!='直接上门' and one_channel!='老带新' limit 0,1";
            ReservationsInfo reservationsInfo = sqlMapper.selectOne(sql2, ReservationsInfo.class);
            if (reservationsInfo != null) {
                String updatesql = "update reservations_info set status='预约',first_visit_date=null where id='" + customerInfo.getReservationsId() + "'";
                sqlMapper.update(updatesql);
                String delsql = "delete from distinction_customer_status where reservations_id='" + customerInfo.getReservationsId() + "'" +
                        " and arrival_store='" + ShiroKit.getUser().getOutpatientName() + "' and status=1 ";
                sqlMapper.delete(delsql);
            } else {
                String sql3 = "select id from reservations_info where id='" + customerInfo.getReservationsId() + "' " +
                        "and left(first_visit_date,10) = '" + (DateTimeKit.now()).substring(0, 10) + "' and (one_channel='直接上门' or one_channel='老带新') limit 0,1";
                ReservationsInfo reservationsInfo1 = sqlMapper.selectOne(sql3, ReservationsInfo.class);
                if (reservationsInfo1 != null) {
                    String deletesql = "delete from reservations_info where id='" + customerInfo.getReservationsId() + "'";
                    sqlMapper.delete(deletesql);
                    String delsql = "delete from distinction_customer_status where reservations_id='" + customerInfo.getReservationsId() + "'" +
                            " and arrival_store='" + ShiroKit.getUser().getOutpatientName() + "' and status=1 ";
                    sqlMapper.delete(delsql);
                }
            }
        } else if (arrivalStatus.equals("1")) {
            String sql = "update " + ShiroKit.getUser().getCustomer_info() + "  set arrival_status ='1' where id = '" + customerId + "'";
            sqlMapper.update(sql);
        }
        webSocket.sendMessageViews("回退", ShiroKit.getUser().getAbbreviation());
        return 1;
    }

    /**
     * 添加随访
     *
     * @return
     */
    @RequestMapping(value = "/addDoctorContent", method = RequestMethod.POST)
    @ResponseBody
    public int addDoctorContent(String customerId, String doctor, String revisitTime,
                                String remarks, String reservationsId, String arrivalStore) {
        String sqlCus = "select arrival_store as arrivalStore from " + ShiroKit.getUser().getCustomer_info() + " where id='" + customerId + "' limit 0,1";
        CustomerInfo info = sqlMapper.selectOne(sqlCus, CustomerInfo.class);
        String sql = "insert into return_doctor_visit_info (reservations_id,customer_id,revisit,revisit_time," +
                "outpatient_name,doctor,remarks,create_time) values ('" + reservationsId
                + "','" + customerId + "','" + doctor + "','" + revisitTime + "','" + ShiroKit.getUser().getOutpatientName()
                + "','" + doctor + "','" + remarks + "','" + DateTimeKit.now() + "')";
        return sqlMapper.insert(sql);
    }

    /**
     * 保存  在随访
     */
    @RequestMapping(value = "/addDoctorContent2", method = RequestMethod.POST)
    @ResponseBody
    public int addDoctorContent2(String customerId, String doctor, String revisitContent, String revisitTime,
                                 String remarks, String reservationsId, String arrivalStore, String createName, String revisit) {
        String sql = "insert into return_doctor_visit_info (reservations_id,customer_id,revisit,revisit_time," +
                "outpatient_name,doctor,remarks,revisit_content,create_name,revisit_status,create_time) values ('" + reservationsId
                + "','" + customerId + "','" + revisit + "','" + revisitTime + "','" + ShiroKit.getUser().getOutpatientName()
                + "','" + doctor + "','" + remarks + "','" + revisitContent + "','" + createName + "','" + 1 + "','" + DateTimeKit.now() + "')";
        sqlMapper.insert(sql);
        String insertInto = "update " + ShiroKit.getUser().getCustomer_info() + " a set a.visit_status='1',a.first_return_settings='1' where id='" + customerId + "'";
        //插入随访日志
        String sq11 = "INSERT INTO `doctor_visit_info_log` (createtime,single_person,logtype, `userid`," +
                " `succeed`,outpatient_name ,`message`,customer_id,reservations_id) VALUES " +
                " ('" + DateTimeKit.now() + "','" + ShiroKit.getUser().getAccount() + "','新增随访','" + ShiroKit.getUser().getId() + "','成功','" + ShiroKit.getUser().getOutpatientName() +
                "','随访时间：" + revisitTime + " </br>\n随访医生：" + doctor + " </br>\n随访人员：" + revisit + "</br>\n创建人:" + createName + "</br>\n创建内容：" + remarks + " " +
                "</br>\n随访结果：" + revisitContent + "</br>\n随访状态：待计划 </br>\n','" + customerId + "','" + reservationsId + "');";
        sqlMapper.insert(sq11);
        return sqlMapper.update(insertInto);
    }

    /**
     * 表格中 修改  保存在随访
     */
    @RequestMapping(value = "/addDoctorContents", method = RequestMethod.POST)
    @ResponseBody
    public int addDoctorContents(String customerId, String doctor, String revisitTime,
                                 String remarks, String reservationsId, String arrivalStore, String createName, String revisit) {
        String sql = "insert into return_doctor_visit_info (reservations_id,customer_id,revisit,revisit_time," +
                "outpatient_name,doctor,remarks,create_name,revisit_status,create_time) values ('" + reservationsId
                + "','" + customerId + "','" + revisit + "','" + revisitTime + "','" + ShiroKit.getUser().getOutpatientName()
                + "','" + doctor + "','" + remarks + "','" + createName + "','" + 1 + "','" + DateTimeKit.now() + "')";
        sqlMapper.insert(sql);
        String insertInto = "update " + ShiroKit.getUser().getCustomer_info() + " a set a.visit_status='1' where id='" + customerId + "'";
        return sqlMapper.update(insertInto);
    }

    /**
     * 随访完成
     */
    @RequestMapping(value = "/addDoctorContent3", method = RequestMethod.POST)
    @ResponseBody
    public int addDoctorContent3(String customerId, String doctor, String revisitContent, String revisitTime,
                                 String remarks, String reservationsId, String arrivalStore, String createName, String revisit) {
        int revisitStatus = 2;
        String sql = "insert into return_doctor_visit_info (reservations_id,customer_id,revisit,revisit_time," +
                "outpatient_name,doctor,remarks,revisit_content,create_name,revisit_status,create_time) values ('" + reservationsId
                + "','" + customerId + "','" + revisit + "','" + revisitTime + "','" + ShiroKit.getUser().getOutpatientName()
                + "','" + doctor + "','" + remarks + "','" + revisitContent + "','" + createName
                + "','" + revisitStatus + "','" + DateTimeKit.now() + "')";
        sqlMapper.insert(sql);
        String insertInto = "update " + ShiroKit.getUser().getCustomer_info() + " a set a.visit_status='1',a.first_return_settings='1' where id='" + customerId + "'";
        //插入随访日志
        String sq11 = "INSERT INTO `doctor_visit_info_log` (createtime,single_person,logtype, `userid`," +
                " `succeed`,outpatient_name ,`message`,customer_id,reservations_id) VALUES " +
                " ('" + DateTimeKit.now() + "','" + ShiroKit.getUser().getAccount() + "','新增随访','" + ShiroKit.getUser().getId() + "','成功','" + ShiroKit.getUser().getOutpatientName() +
                "','随访时间：" + revisitTime + " </br>\n随访医生：" + doctor + " </br>\n随访人员：" + revisit + "</br>\n创建人:" + createName + "</br>\n创建内容：" + remarks + " " +
                "</br>\n随访结果：" + revisitContent + "</br>\n随访状态：随访完成 </br>\n','" + customerId + "','" + reservationsId + "');";
        sqlMapper.insert(sq11);
        return sqlMapper.update(insertInto);
    }

    /**
     * 随访未完成
     */
    @RequestMapping(value = "/addDoctorContent4", method = RequestMethod.POST)
    @ResponseBody
    public int addDoctorContent4(String customerId, String doctor, String revisitContent, String revisitTime,
                                 String remarks, String reservationsId, String arrivalStore, String createName, String revisit) {
        int revisitStatus = 3;
        String sql = "insert into return_doctor_visit_info (reservations_id,customer_id,revisit,revisit_time," +
                "outpatient_name,doctor,remarks,revisit_content,create_name,revisit_status,create_time) values ('" + reservationsId
                + "','" + customerId + "','" + revisit + "','" + revisitTime + "','" + ShiroKit.getUser().getOutpatientName()
                + "','" + doctor + "','" + remarks + "','" + revisitContent + "','" + createName
                + "','" + revisitStatus + "','" + DateTimeKit.now() + "')";
        sqlMapper.insert(sql);
        String insertInto = "update " + ShiroKit.getUser().getCustomer_info() + " a set a.visit_status='1',a.first_return_settings='1' where id='" + customerId + "'";
        return sqlMapper.update(insertInto);
    }

    /**
     * 随访取消
     */
    @RequestMapping(value = "/addDoctorContent5", method = RequestMethod.POST)
    @ResponseBody
    public int addDoctorContent5(String customerId, String doctor, String revisitContent, String revisitTime,
                                 String remarks, String reservationsId, String arrivalStore, String createName, String revisit) {
        int revisitStatus = 4;
        String sql = "insert into return_doctor_visit_info (reservations_id,customer_id,revisit,revisit_time," +
                "outpatient_name,doctor,remarks,revisit_content,create_name,revisit_status,create_time) values ('" + reservationsId
                + "','" + customerId + "','" + revisit + "','" + revisitTime + "','" + ShiroKit.getUser().getOutpatientName()
                + "','" + doctor + "','" + remarks + "','" + revisitContent + "','" + createName
                + "','" + revisitStatus + "','" + DateTimeKit.now() + "')";
        sqlMapper.insert(sql);
        String insertInto = "update " + ShiroKit.getUser().getCustomer_info() + " a set a.visit_status='1',a.first_return_settings='1' where id='" + customerId + "'";
        return sqlMapper.update(insertInto);
    }

    /**
     * 修改  随访保存
     */
    @RequestMapping(value = "/updateDoctorContent", method = RequestMethod.POST)
    @ResponseBody
    public int updateDoctorContent(String doctor, String createName,
                                   String revisitTime, String revisitContent, String doctorVisitId,
                                   String remarks, String customerId, String reservationsId, String revisit) {
        String updatesql = "update " + ShiroKit.getUser().getCustomer_info() + " set arrival_status=6 where id='" + customerId + "' and (arrival_status=1 or arrival_status=7);";
        String sql = "update return_doctor_visit_info set doctor='" + doctor + "',create_name='" + createName
                + "',revisit_time='" + revisitTime + "',revisit_content='" + revisitContent
                + "',remarks='" + remarks + "',revisit='" + revisit + "' where reservations_id='" + reservationsId + "' and id='" + doctorVisitId + "'";
        sqlMapper.update(updatesql);
        //插入随访日志
        String sq11 = "INSERT INTO `doctor_visit_info_log` (createtime,single_person,logtype, `userid`," +
                " `succeed`,outpatient_name ,`message`,customer_id,reservations_id) VALUES " +
                " ('" + DateTimeKit.now() + "','" + ShiroKit.getUser().getAccount() + "','修改随访','" + ShiroKit.getUser().getId() + "','成功','" + ShiroKit.getUser().getOutpatientName() +
                "','随访结果：" + revisitContent + "</br>\n随访状态：待计划->待计划</br>\n','" + customerId + "','" + reservationsId + "');";
        sqlMapper.insert(sq11);
        return sqlMapper.update(sql);
    }

    /**
     * 修改 完成随访
     */
    @RequestMapping(value = "/updateDoctorContent1", method = RequestMethod.POST)
    @ResponseBody
    public int updateDoctorContent1(String doctor, String createName,
                                    String revisitTime, String revisitContent, String doctorVisitId,
                                    String remarks, String reservationsId, String customerId, String revisit) {
        String sql = "update return_doctor_visit_info set doctor='" + doctor + "',create_name='" + createName
                + "',revisit_time='" + revisitTime + "',revisit_content='" + revisitContent
                + "',remarks='" + remarks + "',revisit='" + revisit + "',revisit_status='2' where reservations_id='" + reservationsId + "' and id='" + doctorVisitId + "'";
        //插入随访日志
        String sq11 = "INSERT INTO `doctor_visit_info_log` (createtime,single_person,logtype, `userid`," +
                " `succeed`,outpatient_name ,`message`,customer_id,reservations_id) VALUES " +
                " ('" + DateTimeKit.now() + "','" + ShiroKit.getUser().getAccount() + "','修改随访','" + ShiroKit.getUser().getId() + "','成功','" + ShiroKit.getUser().getOutpatientName() +
                "','随访结果：" + revisitContent + "</br>\n随访状态：待计划->回访完成</br>\n','" + customerId + "','" + reservationsId + "');";
        sqlMapper.insert(sq11);
        return sqlMapper.update(sql);
    }

    /**
     * 修改 随访未完成
     */
    @RequestMapping(value = "/updateDoctorContent2", method = RequestMethod.POST)
    @ResponseBody
    public int updateDoctorContent2(String doctor, String createName,
                                    String revisitTime, String revisitContent, String doctorVisitId,
                                    String remarks, String reservationsId, String revisit) {
        String sql = "update return_doctor_visit_info set doctor='" + doctor + "',create_name='" + createName
                + "',revisit_time='" + revisitTime + "',revisit_content='" + revisitContent
                + "',remarks='" + remarks + "',revisit='" + revisit + "',revisit_status='3' where reservations_id='" + reservationsId + "' and id='" + doctorVisitId + "'";
        return sqlMapper.update(sql);
    }

    /**
     * 图片删除
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/imgDel", method = RequestMethod.POST)
    @ResponseBody
    public String imgDel(String id) {
        String sql = "delete from icon_info where id = '" + id + "'";
        String selectSql2 = "select * from icon_info t where id='" + id + "' limit 1";
        IconInfo iconInfo = sqlMapper.selectOne(selectSql2, IconInfo.class);
        String customerSql = "select id,customer_name,customer_phone from " + ShiroKit.getUser().getCustomer_info() + " where reservations_id='" + iconInfo.getReservationsId() + "' limit 1";
        CustomerInfo customerInfo = sqlMapper.selectOne(customerSql, CustomerInfo.class);
        if (customerInfo == null) {
            return "/doNoClose.html";
        }
        String inertsq1 = "INSERT INTO `icon_info_log` (createtime,reservations_id,icon_id,single_person,logtype, `userid`, `customer_name`,`customer_phone`," +
                " `succeed`,outpatient_name ,`message`,customer_id,img_url) VALUES " +
                " ('" + DateTimeKit.now() + "','" + iconInfo.getReservationsId() + "','" + id + "','" + ShiroKit.getUser().getAccount() + "','删除影像','" + ShiroKit.getUser().getId() + "', '"
                + customerInfo.getCustomerName() + "', '" + customerInfo.getCustomerPhone() + "','成功','" + ShiroKit.getUser().getOutpatientName() +
                "','" + ShiroKit.getUser().getAccount() + " 把 " + customerInfo.getCustomerName() + " 的影像在:" + DateTimeKit.now() + "进行删除','" + iconInfo.getCustomerId() + "','" + iconInfo.getImageUrl() + "');";
        sqlMapper.insert(inertsq1);//插入删除日志
        sqlMapper.delete(sql);
        return "1";
    }


    /**
     * 选择上传影像类型
     */
    @RequestMapping("/openIconType/{cri}")
    public String openIconType(@PathVariable String cri, Model model) {
        String reservationsId = cri.split(",")[0];
        String customerId = cri.split(",")[1];
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        //得到项目
        String sql2 = "select distinct (p.pay_service_name) as payServiceName,t.pay_service_id as payServiceId from  " + ShiroKit.getUser().getDeal_info() + "  t " +
                "left join " + ShiroKit.getUser().getPay_service_info() + " p on p.id=t.pay_service_id " +
                "where reservations_id = '" + reservationsId + "' ";
        List<ReservationsInfo> reservationsInfo = sqlMapper.selectList(sql2, ReservationsInfo.class);
        model.addAttribute("reservationsInfo", reservationsInfo);
        //获得患者的到店时间
        String sql1 = "select left(arrival_time,19) as arrivalTime from " + ShiroKit.getUser().getCustomer_info() + " " +
                "where arrival_status!=1 and arrival_status!=6 and arrival_status!=7 and arrival_status!=8 and arrival_status!=9 and arrival_status!=10 and reservations_id = '" + reservationsId + "' and arrival_time is not null order by arrival_time DESC ";
        List<CustomerInfo> customerList = sqlMapper.selectList(sql1, CustomerInfo.class);
        model.addAttribute("customerList", customerList);
        model.addAttribute("customerId", customerId);
        model.addAttribute("reservationsId", reservationsId);
        return PREFIX + "openIconType.html";
    }

    /**
     * 选择项目
     */
    @RequestMapping("/doctor_payName/{cri}")
    public String doctorPayName(@PathVariable String cri, Model model) {
        String reservationsId = cri.split(",")[0];
        String customerId = cri.split(",")[1];
        String doctor = cri.split(",")[2];
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        //得到项目
        String sql2 = "select distinct (p.pay_service_name) as payServiceName,t.pay_service_id as payServiceId from  " + ShiroKit.getUser().getDeal_info() + "  t " +
                "left join " + ShiroKit.getUser().getPay_service_info() + " p on p.id=t.pay_service_id " +
                "where reservations_id = '" + reservationsId + "' ";
        List<ReservationsInfo> reservationsInfo = sqlMapper.selectList(sql2, ReservationsInfo.class);
        model.addAttribute("reservationsInfo", reservationsInfo);
        //获得患者的到店时间
        String sql1 = "select left(arrival_time,19) as arrivalTime from " + ShiroKit.getUser().getCustomer_info() + " " +
                "where arrival_status!=1 and arrival_status!=6 and arrival_status!=7 and arrival_status!=8 and arrival_status!=9 and arrival_status!=10 and reservations_id = '" + reservationsId + "' and arrival_time is not null order by arrival_time DESC ";
        List<CustomerInfo> customerList = sqlMapper.selectList(sql1, CustomerInfo.class);
        model.addAttribute("customerList", customerList);
        model.addAttribute("customerId", customerId);
        model.addAttribute("doctor", doctor);
        model.addAttribute("reservationsId", reservationsId);
        return PREFIX + "doctor_payName.html";
    }
    /**
     * 保存看诊项目
     */
//    @RequestMapping(value = "/save_payName", method = RequestMethod.POST)
//    @ResponseBody
//    public int savePayName(String customerId,String reservationsId,String optionName,String doctor,String finnallyTime) {
//        String sqls1="select * from icon_info_status a where status in (0,1) and reservations_id='"+reservationsId+"'";
//        List<iconInfoStatus> list1=sqlMapper.selectList(sqls1,iconInfoStatus.class);
//        if(list1.size()==0) {
//            String inertsq1 = "INSERT INTO `icon_info_status` (create_time,reservations_id,customer_id,status,doctor,outpatient_name,option_name,finnally_time) VALUES " +
//                    " ('" + DateTimeKit.now() + "','" + reservationsId + "','" + customerId + "',1,'" + doctor + "','" + ShiroKit.getUser().getOutpatientName() + "','" + optionName + "','" + finnallyTime + "');";
//            sqlMapper.insert(inertsq1);
//        }else{
//            String upd="update icon_info_status a set status=1 where reservations_id='"+reservationsId+"'";
//            sqlMapper.update(upd);
//        }
//        return 1;
//    }

    /**
     * 选择上传影像类型
     */
    @RequestMapping("/openIconType1/{cri}")
    public String openIconType1(@PathVariable String cri, Model model) {
        String reservationsId = cri.split(",")[0];
        String customerId = cri.split(",")[1];
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        //得到项目
        String sql2 = "select distinct (p.pay_service_name) as payServiceName,t.pay_service_id as payServiceId from  " + ShiroKit.getUser().getDeal_info() + "  t " +
                "left join " + ShiroKit.getUser().getPay_service_info() + " p on p.id=t.pay_service_id " +
                "where reservations_id = '" + reservationsId + "' ";
        List<ReservationsInfo> reservationsInfo = sqlMapper.selectList(sql2, ReservationsInfo.class);
        model.addAttribute("reservationsInfo", reservationsInfo);
        //获得患者的到店时间
        String sql1 = "select arrival_time as arrivalTime from " + ShiroKit.getUser().getCustomer_info() + " " +
                " where arrival_status!=1 and arrival_status!=6 and arrival_status!=7 and arrival_status!=8 and arrival_status!=9 and arrival_status!=10" +
                " and arrival_time is not null and reservations_id = '" + reservationsId + "' and arrival_time is not null order by arrival_time DESC ";
        List<CustomerInfo> customerList = sqlMapper.selectList(sql1, CustomerInfo.class);
        model.addAttribute("customerList", customerList);
        model.addAttribute("customerId", customerId);
        model.addAttribute("reservationsId", reservationsId);
        return PREFIX + "openIconType1.html";
    }

    /**
     * 选择上传影像
     */
    @RequestMapping("/openIconTypes/{ids}")
    public String openIconTypes(@PathVariable String ids, Model model) {
        String reservationsId = ids.split(",")[0];
        String customerId = ids.split(",")[1];
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        //得到项目
        String sql2 = "select distinct (p.pay_service_name) as payServiceName,t.pay_service_id as payServiceId from  " + ShiroKit.getUser().getDeal_info() + "  t " +
                "left join " + ShiroKit.getUser().getPay_service_info() + " p on p.id=t.pay_service_id " +
                "where reservations_id = '" + reservationsId + "' ";
        List<ReservationsInfo> reservationsInfo = sqlMapper.selectList(sql2, ReservationsInfo.class);
        model.addAttribute("reservationsInfo", reservationsInfo);
        //获得患者的到店时间
        String sql1 = "select left(arrival_time,19) as arrivalTime from " + ShiroKit.getUser().getCustomer_info() + " " +
                "where arrival_status!=1 and arrival_status!=6 and arrival_status!=7 and arrival_status!=8 and arrival_status!=9 and arrival_status!=10 and reservations_id = '" + reservationsId + "' and arrival_time is not null order by arrival_time DESC";
        List<CustomerInfo> customerList = sqlMapper.selectList(sql1, CustomerInfo.class);
        if (ShiroKit.getUser().getDoctorInfoList() == null) {
            String doctorListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + ShiroKit.getUser().getAbbreviation() + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            List<DoctorInfo> doctorInfoList=sqlMapper.selectList(doctorListSql,DoctorInfo.class);
            ShiroKit.getUser().setDoctorInfoList(doctorInfoList);
        }
        model.addAttribute("doctorList", ShiroKit.getUser().getDoctorInfoList());
        //删除临时icon_infos1 的数据
        String deleteSql = "delete from icon_infos1 where reservations_id ='" + reservationsId + "'";
        sqlMapper.delete(deleteSql);
        String randomNumbersql = "select DATE_FORMAT(now(),'%Y%m%d%k%i%S') as randomNumber from dual";
        DaulInfo infos = sqlMapper.selectOne(randomNumbersql, DaulInfo.class);
        model.addAttribute("userName", ShiroKit.getUser().getAccount());
        model.addAttribute("customerList", customerList);
        model.addAttribute("reservationsId", reservationsId);
        model.addAttribute("customerId", customerId);
        model.addAttribute("num", infos.getRandomNumber());
        return PREFIX + "openIconTypes.html";
    }

    /**
     * 修改上传打分影像
     */
    @RequestMapping("/openUpdateIconTypes/{ids}")
    public String openUpdateIconTypes(@PathVariable String ids, Model model) {
        String num = ids.split(",")[0];
        String reservationsId = ids.split(",")[1];
        String customerId = ids.split(",")[2];
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        //得到项目
        String sql2 = "select distinct (p.pay_service_name) as payServiceName,t.pay_service_id as payServiceId from  " + ShiroKit.getUser().getDeal_info() + "  t " +
                "left join " + ShiroKit.getUser().getPay_service_info() + " p on p.id=t.pay_service_id " +
                "where reservations_id = '" + reservationsId + "' ";
        List<ReservationsInfo> reservationsInfo = sqlMapper.selectList(sql2, ReservationsInfo.class);
        model.addAttribute("reservationsInfo", reservationsInfo);
        //获得患者的到店时间
        String sql1 = "select left(arrival_time,19) as arrivalTime from " + ShiroKit.getUser().getCustomer_info() + " " +
                "where arrival_status!=1 and arrival_status!=6 and arrival_status!=7 and arrival_status!=8 and arrival_status!=9 and arrival_status!=10 and reservations_id = '" + reservationsId + "' and arrival_time is not null order by arrival_time DESC";
        List<CustomerInfo> customerList = sqlMapper.selectList(sql1, CustomerInfo.class);
        if (ShiroKit.getUser().getDoctorInfoList() == null) {
            String doctorListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + ShiroKit.getUser().getAbbreviation() + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            List<DoctorInfo> doctorInfoList=sqlMapper.selectList(doctorListSql,DoctorInfo.class);
            ShiroKit.getUser().setDoctorInfoList(doctorInfoList);
        }
        model.addAttribute("doctorList", ShiroKit.getUser().getDoctorInfoList());
        String selesql = "select * from icon_infos where num='" + num + "' and reservations_id='" + reservationsId + "' " +
                " order by icon_name1 desc";
        List<IconInfo> iconInfoList = sqlMapper.selectList(selesql, IconInfo.class);
        model.addAttribute("userName", ShiroKit.getUser().getAccount());
        model.addAttribute("customerList", customerList);
        model.addAttribute("reservationsId", reservationsId);
        model.addAttribute("iconInfoList", iconInfoList);
        model.addAttribute("customerId", customerId);
        model.addAttribute("num", num);
        return PREFIX + "updateIconTypes.html";
    }

    /**
     * 初诊打印病历
     */
    @RequestMapping("/doctor_print/{id}")
    public String doctor_print(@PathVariable String id, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        if (ToolUtil.isEmpty(id)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        //先查询病例主表单个实体
        String sql = "select * from case_info t1 where t1.id='" + id + "' limit 1";
        CaseInfo caseInfo = sqlMapper.selectOne(sql, CaseInfo.class);
        //然后查询牙位集合,把每种检测项的多个牙位装入到对应的牙位集合里面去
        String sql1 = "select * from tooth_site t1 where t1.case_id='" + id + "' order by id";
        List<ToothSite> toothSiteList = sqlMapper.selectList(sql1, ToothSite.class);
        for (ToothSite toothSite : toothSiteList) {
            //根据对应的牙位类型,给病例实体的对应牙位属性赋值,把每组多个牙位信息通过&&拼接成一个字符串属性传到前端
            if (toothSite.getYaType().equals("1")) {
                caseInfo.getToothSite1List().add(toothSite);
            }
            if (toothSite.getYaType().equals("2")) {
                caseInfo.getToothSite2List().add(toothSite);
            }
            if (toothSite.getYaType().equals("3")) {
                caseInfo.getToothSite3List().add(toothSite);
            }
            if (toothSite.getYaType().equals("4")) {
                caseInfo.getToothSite4List().add(toothSite);
            }
            if (toothSite.getYaType().equals("5")) {
                caseInfo.getToothSite5List().add(toothSite);
            }
        }
        if (ShiroKit.getUser().getDoctorInfoList() == null) {
            String doctorListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + ShiroKit.getUser().getAbbreviation() + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            List<DoctorInfo> doctorInfoList=sqlMapper.selectList(doctorListSql,DoctorInfo.class);
            ShiroKit.getUser().setDoctorInfoList(doctorInfoList);
        }
        model.addAttribute("list", ShiroKit.getUser().getDoctorInfoList());
        String selectSql = "select " +
                "  (CASE a.customer_sex  " +
                "  WHEN 1 THEN  " +
                "  '男'  " +
                "  WHEN 2 THEN  " +
                "  '女'  " +
                "  ELSE  " +
                "  '未知'  " +
                "  END  " +
                " ) as sex ,a.* from " + caseInfo.getAbbreviation() + "customer_info a where id= '" + caseInfo.getCustomerId() + "' limit 1";
        CustomerInfo customerInfo = sqlMapper.selectOne(selectSql, CustomerInfo.class);
        String sql22 = "select * from dept where abbreviation='" + tableHead + "' limit 1";
        Dept dept = sqlMapper.selectOne(sql22, Dept.class);
        model.addAttribute("deptInfo", dept);
        model.addAttribute("caseInfo", caseInfo);
        model.addAttribute("customerInfo", customerInfo);
        return PREFIX + "doctor_print.html";
    }

    /**
     * 复诊打印病历
     */
    @RequestMapping("/doctor_prints/{id}")
    public String doctor_prints(@PathVariable String id, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        if (ToolUtil.isEmpty(id)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        //先查询病例主表单个实体
        String sql = "select * from case_info t1 where t1.id='" + id + "' limit 1";
        CaseInfo caseInfo = sqlMapper.selectOne(sql, CaseInfo.class);
        //然后查询牙位集合,把每种检测项的多个牙位装入到对应的牙位集合里面去
        String sql1 = "select * from tooth_site t1 where t1.case_id='" + id + "' order by id";
        List<ToothSite> toothSiteList = sqlMapper.selectList(sql1, ToothSite.class);
        for (ToothSite toothSite : toothSiteList) {
            //根据对应的牙位类型,给病例实体的对应牙位属性赋值,把每组多个牙位信息通过&&拼接成一个字符串属性传到前端
            if (toothSite.getYaType().equals("1")) {
                caseInfo.getToothSite1List().add(toothSite);
            }
            if (toothSite.getYaType().equals("2")) {
                caseInfo.getToothSite2List().add(toothSite);
            }
            if (toothSite.getYaType().equals("3")) {
                caseInfo.getToothSite3List().add(toothSite);
            }
            if (toothSite.getYaType().equals("4")) {
                caseInfo.getToothSite4List().add(toothSite);
            }
            if (toothSite.getYaType().equals("5")) {
                caseInfo.getToothSite5List().add(toothSite);
            }
        }
        if (ShiroKit.getUser().getDoctorInfoList() == null) {
            String doctorListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + ShiroKit.getUser().getAbbreviation() + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            List<DoctorInfo> doctorInfoList=sqlMapper.selectList(doctorListSql,DoctorInfo.class);
            ShiroKit.getUser().setDoctorInfoList(doctorInfoList);
        }
        model.addAttribute("list", ShiroKit.getUser().getDoctorInfoList());
        String selectSql = "select " +
                "  (CASE a.customer_sex  " +
                "  WHEN 1 THEN  " +
                "  '男'  " +
                "  WHEN 2 THEN  " +
                "  '女'  " +
                "  ELSE  " +
                "  '未知'  " +
                "  END  " +
                " ) as sex ,a.* from " + ShiroKit.getUser().getCustomer_info() + " a where id= '" + caseInfo.getCustomerId() + "' limit 1";
        CustomerInfo customerInfo = sqlMapper.selectOne(selectSql, CustomerInfo.class);
        String sql22 = "select * from dept where abbreviation='" + tableHead + "'";
        Dept dept = sqlMapper.selectOne(sql22, Dept.class);
        model.addAttribute("deptInfo", dept);
        model.addAttribute("caseInfo", caseInfo);
        model.addAttribute("customerInfo", customerInfo);
        return PREFIX + "doctor_prints.html";
    }

    /**
     * 初始化下拉预约时间
     */
    @RequestMapping(value = "/diagnoseList", method = RequestMethod.POST)
    @ResponseBody
    public List<DoctorDiagnosisInfo> diagnoseList(String reservationsId, String customerId, Model model) {
        //查询此人的看诊记录
        String sql = "select customer_id as customerId,reservations_id as reservationsId," +
                "outpatient_name as outpatientName,diagnose_time as diagnoseTime " +
                " from doctor_diagnosis_info where reservations_id='" + reservationsId + "'";
        List<DoctorDiagnosisInfo> doctorDiagnosisInfo = sqlMapper.selectList(sql, DoctorDiagnosisInfo.class);
        return doctorDiagnosisInfo;
    }

    /**
     * 上传图片(上传到项目的webapp/static/img)
     */
    @RequestMapping(method = RequestMethod.POST, path = "/uploadIcon/{cri}")
    @ResponseBody
    public String uploadIcon(@RequestPart("file") MultipartFile picture,
                             @PathVariable String cri) {
        String payServiceId = cri.split(",")[0];
        if ("aa".equals(payServiceId)) {
            payServiceId = "";
        }
        String customerId = cri.split(",")[1];
        String reservationsId = cri.split(",")[2];
        String iconType = cri.split(",")[3];
        String remarks = cri.split(",")[4];
        if ("aa".equals(remarks)) {
            remarks = "";
        }
        String alldiagnosetime = cri.split(",")[5];
        String alldiagnose2 = alldiagnosetime + " " + ShiroKit.getUser().getOutpatientName();
//        String realPath = "D:\\8068\\apache-tomcat-8.0.30\\webapps\\ROOT\\yingxiang";
//        String httpUrl = "http://118.123.15.60:8068/yingxiang/";
        //避免出现相同的图片名称  ids
        String ids = CommUtils.getUUID();
        String imageurl = "yingxiang/" + ids + (picture.getOriginalFilename()).substring(1, 5) + ".png";
        try {
//            FileUtils.copyInputStreamToFile(picture.getInputStream(), new File(realPath, ids + (picture.getOriginalFilename()).substring(1, 5) + ".png"));
            aliyunOssUtil.pushSingleFile(picture, imageurl);
            String sql = "insert into  icon_info (customer_id,reservations_id,outpatient_name,add_name," +
                    "add_time,image_url,icon_name,remarks,diagnoseTime,pay_service_id) values ('" + customerId
                    + "','" + reservationsId + "','" + ShiroKit.getUser().getOutpatientName() + "','"
                    + ShiroKit.getUser().getAccount() + "','" + DateTimeKit.now() + "','" + MemberEnumConfig.ossphoeurl + imageurl + "','" + iconType + "','" + remarks + "','" + alldiagnose2 + "','" + payServiceId + "')";
            sqlMapper.insert(sql);
            //插入影像新增日志
            String selectSql2 = "select * from icon_info t where customer_id='" + customerId + "' order by add_time limit 1";
            IconInfo iconInfo = sqlMapper.selectOne(selectSql2, IconInfo.class);
            String customerSql = "select id,customer_name,customer_phone from " + ShiroKit.getUser().getCustomer_info() + " where id='" + customerId + "' limit 1";
            CustomerInfo customerInfo = sqlMapper.selectOne(customerSql, CustomerInfo.class);
            String inertsq1 = "INSERT INTO `icon_info_log` (createtime,reservations_id,icon_id,single_person,logtype, `userid`, `customer_name`,`customer_phone`," +
                    " `succeed`,outpatient_name ,`message`,customer_id) VALUES " +
                    " ('" + DateTimeKit.now() + "','" + iconInfo.getReservationsId() + "','" + iconInfo.getId() + "','" + ShiroKit.getUser().getAccount() + "','新增影像','" + ShiroKit.getUser().getId() + "', '"
                    + customerInfo.getCustomerName() + "', '" + customerInfo.getCustomerPhone() + "','成功','" + ShiroKit.getUser().getOutpatientName() +
                    "','" + ShiroKit.getUser().getAccount() + " 把 " + customerInfo.getCustomerName() + " 的影像在:" + DateTimeKit.now() + "进行上传','" + customerId + "');";
            sqlMapper.insert(inertsq1);//插入删除日志
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        //return realPath;
        return MemberEnumConfig.ossphoeurl + imageurl;
    }

    /**
     * 获得影像信息
     *
     * @return
     */
    @RequestMapping(path = "/getIconInfo/{cri}", method = RequestMethod.POST)
    @ResponseBody
    public List<IconInfo> getIconInfo(@PathVariable String cri, HttpServletRequest request, Model model) {
        List<IconInfo> list = new ArrayList<>();
        String reservationsId = cri.split(",")[1];
        String iconType = cri.split(",")[2];
        String param = "";
        if (StringUtils.isNotBlank(iconType) && !iconType.equals("所有类型")) {
            param += " and i.icon_name = '" + iconType + "' ";
        }
        if (StringUtils.isNotBlank(reservationsId)) {
            param += " and i.reservations_id = '" + reservationsId + "' ";
        }
        try {
            String sql = "  select  i.id ,i.customer_id as customerId,i.reservations_id as reservationsId,i.icon_name as iconName," +
                    "  i.outpatient_name as outpatientName,i.diagnoseTime as diagnoseTime,i.add_name as addName,i.add_time as addTime," +
                    "i.remarks as remarks,i.image_url as imageUrl,p.pay_service_name as payServiceName  from icon_info i " +
                    "left join " + ShiroKit.getUser().getPay_service_info() + " p on p.id=i.pay_service_id  where 1=1 " + param + " order by diagnoseTime DESC";
            list = sqlMapper.selectList(sql, IconInfo.class);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

    /**
     * 上传图片(上传到项目的webapp/static/img)
     */
    @RequestMapping(method = RequestMethod.POST, path = "/uploadIcons/{cri}")
    @ResponseBody
    public String uploadIcons(@RequestPart("file") MultipartFile picture, @PathVariable String cri) {
        String customerId = cri.split(",")[0];
        String reservationsId = cri.split(",")[1];
        String iconType = cri.split(",")[2];
        String num = cri.split(",")[3];
        String iconName1 = "";
        String originalFile2 = "";
        if ("0".equals(iconType)) {
            iconType = "术前";
            iconName1 = "3";
        }
        if ("1".equals(iconType)) {
            iconType = "术中";
            iconName1 = "2";
        }
        if ("2".equals(iconType)) {
            iconType = "术后";
            iconName1 = "1";
        }
        String sql1 = "select * from " + ShiroKit.getUser().getCustomer_info() + " where id= '" + customerId + "'";
        ConsultantInfo info1 = sqlMapper.selectOne(sql1, ConsultantInfo.class);
        String abbreviation = ShiroKit.getUser().getAbbreviation();
        String originalFile1 = "JPG_" + DateTimeKit.now().substring(0, 10);
        if (info1.getCustomerPhone().indexOf("+") != -1) {
            originalFile2 = info1.getCustomerName() + (info1.getCustomerPhone().substring(0, info1.getCustomerPhone().indexOf("+")));
        } else {
            originalFile2 = info1.getCustomerName() + info1.getCustomerPhone();
        }
        String originalFileName = info1.getCustomerName() + "-" + iconType + ".jpg";
        String realPath = "D:\\8068\\apache-tomcat-8.0.30\\webapps\\ROOT\\photo\\" + abbreviation + "\\" + originalFile1 + "\\" + originalFile2;
//        String httpUrl = "http://118.123.15.60:8068/photo/" + abbreviation + "/" + originalFile1 + "/" + originalFile2 + "/";
        String httpUrl = "photo/" + abbreviation + "/" + originalFile1 + "/" + originalFile2 + "/";
        String imageurl = httpUrl + "\\" + originalFileName;
        String httpUrl2 = "photo/" + abbreviation + "/" + originalFile1 + "/" + originalFile2 + "/" + originalFileName;
        try {
            OSSClient ossClient = new OSSClient(MemberEnumConfig.endPoint, MemberEnumConfig.accessKeyId, MemberEnumConfig.accessKeySecret);
            // 文件夹名OSSClient
            final String keySuffixWithSlash = httpUrl2;
            // 判断文件夹是否存在，不存在则创建
            if (!ossClient.doesObjectExist(MemberEnumConfig.backetName, keySuffixWithSlash)) {
                // 创建文件夹
                ossClient.putObject(MemberEnumConfig.backetName, keySuffixWithSlash, new ByteArrayInputStream(new byte[0]));
            }
            // 得到文件夹名
            OSSObject object = ossClient.getObject(MemberEnumConfig.backetName, keySuffixWithSlash);
            String fileDir = object.getKey();
            ossClient.shutdown();
            aliyunOssUtil.pushSingleFile(picture, httpUrl2);
//            FileUtils.copyInputStreamToFile(picture.getInputStream(), new File(realPath, originalFileName));
            String sql = "insert into icon_infos1 (reservations_id,customer_id,outpatient_name,abbreviation,add_name," +
                    "add_time,image_url,icon_name,icon_name1,num) values ('" + reservationsId + "','" + customerId
                    + "','" + ShiroKit.getUser().getOutpatientName() + "','" + abbreviation + "','"
                    + ShiroKit.getUser().getAccount() + "','" + DateTimeKit.now() + "','" + MemberEnumConfig.ossphoeurl + imageurl + "','" + iconType + "','" + iconName1 + "','" + num + "')";
            sqlMapper.insert(sql);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return realPath;
        //return MemberEnumConfig.ossphoeurl+imageurl1;
    }

    /**
     * 上传图片(上传到项目的webapp/static/img)
     */
    @RequestMapping(method = RequestMethod.POST, path = "/uploadIconsUpdate/{cri}")
    @ResponseBody
    public String uploadIconsUpdate(@RequestPart("file") MultipartFile picture, @PathVariable String cri) {
        String iconType = cri.split(",")[2];
        String num = cri.split(",")[3];
        if ("0".equals(iconType)) {
            iconType = "术前";
        }
        if ("1".equals(iconType)) {
            iconType = "术中";
        }
        if ("2".equals(iconType)) {
            iconType = "术后";
        }
        String sql1 = "select * from icon_infos where num= '" + num + "' and icon_name= '" + iconType + "' limit 1;";
        IconInfo info1 = sqlMapper.selectOne(sql1, IconInfo.class);
        String realPath = info1.getImageUrl().replace("http://118.123.15.60:8068/photoScoring/", "D:\\8068\\apache-tomcat-8.0.30\\webapps\\ROOT\\photoScoring\\");
        try {
            FileUtils.copyInputStreamToFile(picture.getInputStream(), new File(realPath));
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return realPath;
    }

    private void deleteFile(OSSClient ossClient, String bucketName, String folder, String key) {
        ossClient.deleteObject(bucketName, folder + key);
        System.out.println("删除" + bucketName + "下的文件" + folder + key + "成功");
    }

    /**
     * 上传图片重命名(上传到项目的webapp/static/img)
     */
    @RequestMapping(method = RequestMethod.POST, path = "/submissionUploadIcons")
    @ResponseBody
    public String submissionUploadIcons(String cri) {
        String abbreviation = ShiroKit.getUser().getAbbreviation();
        String payServiceId = cri.split(",")[0];
        String customerId = cri.split(",")[1];
        String reservationsId = cri.split(",")[2];
        String remarks = cri.split(",")[3];
        String alldiagnosetime = cri.split(",")[4];
        String doctor = cri.split(",")[5];
        String toothPosition = cri.split(",")[6];
        String iconType1 = cri.split(",")[7];
        String iconType2 = cri.split(",")[8];
        String iconType3 = cri.split(",")[9];
        String originalFileName;
        String yoriginalFileName;
        String originalFile2;
        String originalFile3;
        String realNewPath;
        String realPath;
        String httpUrl;
        String imageurl;
        String imageurls;
        if ("payServiceId".equals(payServiceId)) {
            payServiceId = "";
        }
        if ("remarks".equals(remarks)) {
            remarks = "";
        }
        if ("doctor".equals(remarks)) {
            doctor = "";
        }
        String randomNumber = "select DATE_FORMAT(now(),'%Y%m%d%k%i%S') as randomNumber from dual";
        DaulInfo infos = sqlMapper.selectOne(randomNumber, DaulInfo.class);
        String sql1 = "select * from " + ShiroKit.getUser().getCustomer_info() + " where id= '" + customerId + "'";
        ConsultantInfo info1 = sqlMapper.selectOne(sql1, ConsultantInfo.class);
        //String alldiagnose2 = alldiagnosetime + " " + ShiroKit.getUser().getOutpatientName();
        String time = DateTimeKit.now();
        String originalFile1 = "JPG_" + time.substring(0, 10);
        if (info1.getCustomerPhone().indexOf("+") != -1) {
            originalFile2 = infos.getRandomNumber() + info1.getCustomerName() + (info1.getCustomerPhone().substring(0, info1.getCustomerPhone().indexOf("+")));
            originalFile3 = info1.getCustomerName() + (info1.getCustomerPhone().substring(0, info1.getCustomerPhone().indexOf("+")));
        } else {
            originalFile2 = infos.getRandomNumber() + info1.getCustomerName() + info1.getCustomerPhone();
            originalFile3 = info1.getCustomerName() + info1.getCustomerPhone();
        }
        if ("术前".equals(iconType1)) {
            originalFileName = alldiagnosetime.substring(0, 10).replace("-", "") + "_" +
                    alldiagnosetime.split(" ")[1].split(":")[0] +
                    alldiagnosetime.split(" ")[1].split(":")[1] + alldiagnosetime.split(" ")[1].split(":")[2] + "-" +
                    info1.getCustomerName() + "-" + iconType1 + "-" + toothPosition + "-" + doctor + ".jpg";
            yoriginalFileName = info1.getCustomerName() + "-" + iconType1 + ".jpg";
            String httpUrl1 = "photo/" + abbreviation + "/" + originalFile1 + "/" + originalFile3 + "/" + yoriginalFileName;
            String httpUrl2 = "photoScoring/" + abbreviation + "/" + originalFile1 + "/" + originalFile2 + "/" + originalFileName;
            try {
                // 得到文件夹名
                OSSClient ossClient = new OSSClient(MemberEnumConfig.endPoint, MemberEnumConfig.accessKeyId, MemberEnumConfig.accessKeySecret);
                // 文件夹名OSSClient
                final String keySuffixWithSlash = httpUrl2;
                // 判断文件夹是否存在，不存在则创建
                if (!ossClient.doesObjectExist(MemberEnumConfig.backetName, keySuffixWithSlash)) {
                    // 创建文件夹
                    ossClient.putObject(MemberEnumConfig.backetName, keySuffixWithSlash, new ByteArrayInputStream(new byte[0]));
                }
                OSSObject object = ossClient.getObject(MemberEnumConfig.backetName, httpUrl1);
                String fileDir = object.getKey();
                OSSObject object1 = ossClient.getObject(MemberEnumConfig.backetName, httpUrl2);
                String fileDir1 = object1.getKey();
                CopyObjectResult result = ossClient.copyObject(MemberEnumConfig.backetName, fileDir, MemberEnumConfig.backetName, fileDir1);
                System.out.println("ETag: " + result.getETag() + " LastModified: " + result.getLastModified());
                // 关闭OSSClient。
                ossClient.shutdown();
                String sql = "insert into icon_infos (customer_id,outpatient_name,abbreviation,add_name," +
                        "add_time,image_url,icon_name,reservations_id,diagnoseTime,pay_service_id,customer_name,customer_phone,tooth_position,doctor,remarks,icon_name1,num) values ('" + customerId + "'," +
                        "'" + ShiroKit.getUser().getOutpatientName() + "','" + abbreviation + "','"
                        + ShiroKit.getUser().getAccount() + "','" + time + "','" + MemberEnumConfig.ossphoeurl + httpUrl2
                        + "','术前','" + reservationsId + "','" + alldiagnosetime + "','" + payServiceId + "','" + info1.getCustomerName() + "','" + info1.getCustomerPhone() + "','" + toothPosition + "'," +
                        "'" + doctor + "','" + remarks + "','3','" + infos.getRandomNumber() + "')";
                sqlMapper.insert(sql);
                String deleteSql = "delete from icon_infos1 where customer_id='" + customerId + "' and icon_name='术前'";
                sqlMapper.delete(deleteSql);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
        if ("术中".equals(iconType2)) {
            originalFileName = alldiagnosetime.substring(0, 10).replace("-", "") + "_" +
                    alldiagnosetime.split(" ")[1].split(":")[0] +
                    alldiagnosetime.split(" ")[1].split(":")[1] + alldiagnosetime.split(" ")[1].split(":")[2] + "-" +
                    info1.getCustomerName() + "-" + iconType2 + "-" + toothPosition + "-" + doctor + ".jpg";
            yoriginalFileName = info1.getCustomerName() + "-" + iconType2 + ".jpg";
            //新 照片文件夹路径
            realNewPath = "D:\\8068\\apache-tomcat-8.0.30\\webapps\\ROOT\\photoScoring\\" + abbreviation + "\\" + originalFile1 + "\\" + originalFile2;
            httpUrl = "http://118.123.15.60:8068/photoScoring/" + abbreviation + "/" + originalFile1 + "/" + originalFile2 + "/";
            //数据库URL 路径
            imageurl = httpUrl + "\\" + originalFileName;
            imageurls = imageurl.replace("\\", "");
            String httpUrl1 = "photo/" + abbreviation + "/" + originalFile1 + "/" + originalFile3 + "/" + yoriginalFileName;
            String httpUrl2 = "photoScoring/" + abbreviation + "/" + originalFile1 + "/" + originalFile2 + "/" + originalFileName;
            try {
                OSSClient ossClient = new OSSClient(MemberEnumConfig.endPoint, MemberEnumConfig.accessKeyId, MemberEnumConfig.accessKeySecret);
                // 文件夹名OSSClient
                final String keySuffixWithSlash = httpUrl2;
                // 判断文件夹是否存在，不存在则创建
                if (!ossClient.doesObjectExist(MemberEnumConfig.backetName, keySuffixWithSlash)) {
                    // 创建文件夹
                    ossClient.putObject(MemberEnumConfig.backetName, keySuffixWithSlash, new ByteArrayInputStream(new byte[0]));
                }
                OSSObject object = ossClient.getObject(MemberEnumConfig.backetName, httpUrl1);
                String fileDir = object.getKey();
                OSSObject object1 = ossClient.getObject(MemberEnumConfig.backetName, httpUrl2);
                String fileDir1 = object1.getKey();
                CopyObjectResult result = ossClient.copyObject(MemberEnumConfig.backetName, fileDir, MemberEnumConfig.backetName, fileDir1);
                System.out.println("ETag: " + result.getETag() + " LastModified: " + result.getLastModified());
                // 关闭OSSClient。
                ossClient.shutdown();
                String sql = "insert into icon_infos (customer_id,outpatient_name,abbreviation,add_name," +
                        "add_time,image_url,icon_name,reservations_id,diagnoseTime,pay_service_id,customer_name,customer_phone,tooth_position,doctor,remarks,icon_name1,num) values ('" + customerId + "'," +
                        "'" + ShiroKit.getUser().getOutpatientName() + "','" + abbreviation + "','"
                        + ShiroKit.getUser().getAccount() + "','" + time + "','" + MemberEnumConfig.ossphoeurl + httpUrl2
                        + "','术中','" + reservationsId + "','" + alldiagnosetime + "','" + payServiceId + "','" + info1.getCustomerName() + "','" + info1.getCustomerPhone() + "','" + toothPosition + "','" + doctor + "'," +
                        "'" + remarks + "','2','" + infos.getRandomNumber() + "')";
                sqlMapper.insert(sql);
                String deleteSql = "delete from icon_infos1 where customer_id='" + customerId + "' and icon_name='术中'";
                sqlMapper.delete(deleteSql);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
        if ("术后".equals(iconType3)) {
            originalFileName = alldiagnosetime.substring(0, 10).replace("-", "") + "_" +
                    alldiagnosetime.split(" ")[1].split(":")[0] +
                    alldiagnosetime.split(" ")[1].split(":")[1] + alldiagnosetime.split(" ")[1].split(":")[2] + "-" +
                    info1.getCustomerName() + "-" + iconType3 + "-" + toothPosition + "-" + doctor + ".jpg";
            yoriginalFileName = info1.getCustomerName() + "-" + iconType3 + ".jpg";
            //新 照片文件夹路径
            httpUrl = "http://118.123.15.60:8068/photoScoring/" + abbreviation + "/" + originalFile1 + "/" + originalFile2 + "/";
            imageurl = httpUrl + "\\" + originalFileName;
            imageurls = imageurl.replace("\\", "");
            String httpUrl1 = "photo/" + abbreviation + "/" + originalFile1 + "/" + originalFile3 + "/" + yoriginalFileName;
            String httpUrl2 = "photoScoring/" + abbreviation + "/" + originalFile1 + "/" + originalFile2 + "/" + originalFileName;
            try {
                OSSClient ossClient = new OSSClient(MemberEnumConfig.endPoint, MemberEnumConfig.accessKeyId, MemberEnumConfig.accessKeySecret);
                // 文件夹名OSSClient
                final String keySuffixWithSlash = httpUrl2;
                // 判断文件夹是否存在，不存在则创建
                if (!ossClient.doesObjectExist(MemberEnumConfig.backetName, keySuffixWithSlash)) {
                    // 创建文件夹
                    ossClient.putObject(MemberEnumConfig.backetName, keySuffixWithSlash, new ByteArrayInputStream(new byte[0]));
                }
                OSSObject object = ossClient.getObject(MemberEnumConfig.backetName, httpUrl1);
                String fileDir = object.getKey();
                OSSObject object1 = ossClient.getObject(MemberEnumConfig.backetName, httpUrl2);
                String fileDir1 = object1.getKey();
                CopyObjectResult result = ossClient.copyObject(MemberEnumConfig.backetName, fileDir, MemberEnumConfig.backetName, fileDir1);
                System.out.println("ETag: " + result.getETag() + " LastModified: " + result.getLastModified());
                // 关闭OSSClient。
                ossClient.shutdown();
                String sql = "insert into icon_infos (customer_id,outpatient_name,abbreviation,add_name," +
                        "add_time,image_url,icon_name,reservations_id,diagnoseTime,pay_service_id,customer_name,customer_phone,tooth_position,doctor,remarks,icon_name1,num) values ('" + customerId + "'," +
                        "'" + ShiroKit.getUser().getOutpatientName() + "','" + abbreviation + "','"
                        + ShiroKit.getUser().getAccount() + "','" + time + "','" + MemberEnumConfig.ossphoeurl + httpUrl2
                        + "','术后','" + reservationsId + "','" + alldiagnosetime + "','" + payServiceId + "','" + info1.getCustomerName() + "','" + info1.getCustomerPhone() + "','" + toothPosition + "','" + doctor + "'," +
                        "'" + remarks + "','1','" + infos.getRandomNumber() + "')";
                sqlMapper.insert(sql);
                String deleteSql = "delete from icon_infos1 where customer_id='" + customerId + "' and icon_name='术后'";
                sqlMapper.delete(deleteSql);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        } else {
            return "";
        }
        return MemberEnumConfig.ossphoeurl;
    }

    /**
     * update上传图片
     */
    @RequestMapping(method = RequestMethod.POST, path = "/updateUploadIcons")
    @ResponseBody
    public int updateUploadIcons(String cri) {
        String payServiceId = cri.split(",")[0];
        String remarks = cri.split(",")[3];
        String alldiagnosetime = cri.split(",")[4];
        String doctor = cri.split(",")[5];
        String toothPosition = cri.split(",")[6];
        String num = cri.split(",")[7];
        if ("payServiceId".equals(payServiceId)) {
            payServiceId = "";
        }
        if ("remarks".equals(remarks)) {
            remarks = "";
        }
        if ("doctor".equals(remarks)) {
            doctor = "";
        }
        String abbreviation = ShiroKit.getUser().getAbbreviation();
        String selSql = "select id,image_url,customer_name,customer_phone,icon_name from icon_infos where num='" + num + "';";
        List<QualityAssuranceInfo> iconInfoList = sqlMapper.selectList(selSql, QualityAssuranceInfo.class);
        String time = DateTimeKit.now();
        String originalFile1 = "JPG_" + time.substring(0, 10);
        if (iconInfoList.size() > 0) {
            for (QualityAssuranceInfo iconInfo : iconInfoList) {
                if (iconInfo.getIconName().equals("术前")) {
                    String originalFileName = alldiagnosetime.substring(0, 10).replace("-", "") + "_" +
                            alldiagnosetime.split(" ")[1].split(":")[0] +
                            alldiagnosetime.split(" ")[1].split(":")[1] + alldiagnosetime.split(" ")[1].split(":")[2] + "-" +
                            iconInfo.getCustomerName() + "-" + "术前" + "-" + toothPosition + "-" + doctor + ".jpg";
                    String originalFile2 = num + iconInfo.getCustomerName() + iconInfo.getCustomerPhone();
                    //修改前照片路径
                    String realPath = iconInfo.getImageUrl().replace("http://118.123.15.60:8068/photoScoring/", "D:\\8068\\apache-tomcat-8.0.30\\webapps\\ROOT\\photoScoring\\");
                    //新 照片文件夹路径
                    String realNewPath = "D:\\8068\\apache-tomcat-8.0.30\\webapps\\ROOT\\photoScoring\\" + abbreviation + "\\" + originalFile1 + "\\" + originalFile2;
                    String httpUrl = "http://118.123.15.60:8068/photoScoring/" + abbreviation + "/" + originalFile1 + "/" + originalFile2 + "/";
                    //数据库URL 路径
                    String imageurl = httpUrl + "\\" + originalFileName;
                    try {
                        File fileFrom = new File(realPath);
                        File fileTo = new File(realNewPath);
                        if (!fileTo.exists()) {//判断文件夹是否创建,没有创建则创建新文件夹
                            fileTo.mkdirs();
                        }
                        System.out.println(fileTo + "\\" + fileFrom.getName());
                        if (fileFrom.renameTo(new File(fileTo + "\\" + originalFileName))) {
                            System.out.println("File is moved successful!");
                        } else {
                            System.out.println("File is failed to move!");
                        }
                        String sql = "update icon_infos a set tooth_position='" + toothPosition + "',remarks='" + remarks + "',doctor='" + doctor + "',diagnoseTime='" + alldiagnosetime + "'," +
                                "pay_service_id='" + payServiceId + "',image_url='" + imageurl + "' where id= '" + iconInfo.getId() + "';";
                        sqlMapper.update(sql);
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
                if (iconInfo.getIconName().equals("术中")) {
                    String originalFileName = alldiagnosetime.substring(0, 10).replace("-", "") + "_" +
                            alldiagnosetime.split(" ")[1].split(":")[0] +
                            alldiagnosetime.split(" ")[1].split(":")[1] + alldiagnosetime.split(" ")[1].split(":")[2] + "-" +
                            iconInfo.getCustomerName() + "-" + "术中" + "-" + toothPosition + "-" + doctor + ".jpg";
                    String originalFile2 = num + iconInfo.getCustomerName() + iconInfo.getCustomerPhone();
                    //修改前照片路径
                    String realPath = iconInfo.getImageUrl().replace("http://118.123.15.60:8068/photoScoring/", "D:\\8068\\apache-tomcat-8.0.30\\webapps\\ROOT\\photoScoring\\");
                    //新 照片文件夹路径
                    String realNewPath = "D:\\8068\\apache-tomcat-8.0.30\\webapps\\ROOT\\photoScoring\\" + abbreviation + "\\" + originalFile1 + "\\" + originalFile2;
                    String httpUrl = "http://118.123.15.60:8068/photoScoring/" + abbreviation + "/" + originalFile1 + "/" + originalFile2 + "/";
                    //数据库URL 路径
                    String imageurl = httpUrl + "\\" + originalFileName;
                    try {
                        File fileFrom = new File(realPath);
                        File fileTo = new File(realNewPath);
                        if (!fileTo.exists()) {//判断文件夹是否创建,没有创建则创建新文件夹
                            fileTo.mkdirs();
                        }
                        System.out.println(fileTo + "\\" + fileFrom.getName());
                        if (fileFrom.renameTo(new File(fileTo + "\\" + originalFileName))) {
                            System.out.println("File is moved successful!");
                        } else {
                            System.out.println("File is failed to move!");
                        }
                        String sql = "update icon_infos a set tooth_position='" + toothPosition + "',remarks='" + remarks + "',doctor='" + doctor + "',diagnoseTime='" + alldiagnosetime + "'," +
                                "pay_service_id='" + payServiceId + "',image_url='" + imageurl + "' where id= '" + iconInfo.getId() + "';";
                        sqlMapper.update(sql);
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
                if (iconInfo.getIconName().equals("术后")) {
                    String originalFileName = alldiagnosetime.substring(0, 10).replace("-", "") + "_" +
                            alldiagnosetime.split(" ")[1].split(":")[0] +
                            alldiagnosetime.split(" ")[1].split(":")[1] + alldiagnosetime.split(" ")[1].split(":")[2] + "-" +
                            iconInfo.getCustomerName() + "-" + "术后" + "-" + toothPosition + "-" + doctor + ".jpg";
                    String originalFile2 = num + iconInfo.getCustomerName() + iconInfo.getCustomerPhone();
                    //修改前照片路径
                    String realPath = iconInfo.getImageUrl().replace("http://118.123.15.60:8068/photoScoring/", "D:\\8068\\apache-tomcat-8.0.30\\webapps\\ROOT\\photoScoring\\");
                    //新 照片文件夹路径
                    String realNewPath = "D:\\8068\\apache-tomcat-8.0.30\\webapps\\ROOT\\photoScoring\\" + abbreviation + "\\" + originalFile1 + "\\" + originalFile2;
                    String httpUrl = "http://118.123.15.60:8068/photoScoring/" + abbreviation + "/" + originalFile1 + "/" + originalFile2 + "/";
                    //数据库URL 路径
                    String imageurl = httpUrl + "\\" + originalFileName;
                    try {
                        File fileFrom = new File(realPath);
                        File fileTo = new File(realNewPath);
                        if (!fileTo.exists()) {//判断文件夹是否创建,没有创建则创建新文件夹
                            fileTo.mkdirs();
                        }
                        System.out.println(fileTo + "\\" + fileFrom.getName());
                        if (fileFrom.renameTo(new File(fileTo + "\\" + originalFileName))) {
                            System.out.println("File is moved successful!");
                        } else {
                            System.out.println("File is failed to move!");
                        }
                        String sql = "update icon_infos a set tooth_position='" + toothPosition + "',remarks='" + remarks + "',doctor='" + doctor + "',diagnoseTime='" + alldiagnosetime + "'," +
                                "pay_service_id='" + payServiceId + "',image_url='" + imageurl + "' where id= '" + iconInfo.getId() + "';";
                        sqlMapper.update(sql);
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
            }
            return 1;
        } else {
            return 0;
        }
    }

    //获取 图片
    @RequestMapping(value = "/getImgcancel", method = RequestMethod.POST)
    @ResponseBody
    public List<ApprovalProcessInfo> getImg(String num) throws Exception {
        String sql = "select * from icon_infos where num='" + num + "';";
        List<ApprovalProcessInfo> info2 = sqlMapper.selectList(sql, ApprovalProcessInfo.class);
        return info2;
    }

    //获取 图片
    @RequestMapping(value = "/getIntelligentImgcancel1", method = RequestMethod.POST)
    @ResponseBody
    public List<IconInfo> getIntelligentImgcancel1(String reservationsId, String num) throws Exception {
        String sql = "select * from icon_infos1 where reservations_id='" + reservationsId + "' and num='" + num + "' order by icon_name1 DESC;";
        List<IconInfo> iconinfoList = sqlMapper.selectList(sql, IconInfo.class);
        return iconinfoList;
    }

    //获取 图片
    @RequestMapping(value = "/getIntelligentImgcancel", method = RequestMethod.POST)
    @ResponseBody
    public List<IconInfo> getIntelligentImgcancel(String reservationsId, String num) throws Exception {
        String sql = "select * from icon_infos where reservations_id='" + reservationsId + "' and num='" + num + "' order by icon_name1 DESC;";
        List<IconInfo> iconinfoList = sqlMapper.selectList(sql, IconInfo.class);
        return iconinfoList;
    }

    //删除图片
    @RequestMapping(value = "/delteCancel", method = RequestMethod.POST)
    @ResponseBody
    public int delteProcess(String id) throws Exception {
        if (ToolUtil.isEmpty(id)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        //找到文件夹的url
        String selSql = "select id,image_url from icon_infos where id='" + id + "'";
        IconInfo info = sqlMapper.selectOne(selSql, IconInfo.class);
        OSSClient ossClient = new OSSClient(MemberEnumConfig.endPoint, MemberEnumConfig.accessKeyId, MemberEnumConfig.accessKeySecret);
        OSSObject object1 = ossClient.getObject(MemberEnumConfig.backetName, "photoScoring/" + info.getImageUrl().split("photoScoring/")[1]);
        String fileDir1 = object1.getKey();
        try {
            // 删除文件。如需删除文件夹，请将ObjectName设置为对应的文件夹名称。如果文件夹非空，则需要将文件夹下的所有object删除后才能删除该文件夹。
            ossClient.deleteObject(MemberEnumConfig.backetName, fileDir1);
            // 关闭OSSClient。
            ossClient.shutdown();
        } catch (Exception e) {
            throw new Exception("删除oss文件出错");
        } finally {
            ossClient.shutdown();
        }
        String sql = "delete from icon_infos where id='" + id + "'";
        return sqlMapper.delete(sql);
    }

    //删除临时表 图片 以及路径下的文件
    @RequestMapping(value = "/delteCancel2", method = RequestMethod.POST)
    @ResponseBody
    public int delteProcess2(String id) throws Exception {
        if (ToolUtil.isEmpty(id)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        //找到文件夹的url
        String selSql = "select id,image_url from icon_infos1 where id='" + id + "'";
        IconInfo info = sqlMapper.selectOne(selSql, IconInfo.class);
        //        String httpUrl = info.getImageUrl();
//        String urlName = httpUrl.substring(httpUrl.indexOf("photo") + 6).replace("/", "\\");
//        String pathUrl = "D:\\8068\\apache-tomcat-8.0.30\\webapps\\ROOT\\photo\\" + urlName + "";
//        File file = new File(pathUrl); //文件所在的路径
//        deleteDirectory(file);
        OSSClient ossClient = new OSSClient(MemberEnumConfig.endPoint, MemberEnumConfig.accessKeyId, MemberEnumConfig.accessKeySecret);
        OSSObject object1 = ossClient.getObject(MemberEnumConfig.backetName, "photo/" + info.getImageUrl().split("photo/")[1]);
        String fileDir1 = object1.getKey();
        try {
            // 删除文件。如需删除文件夹，请将ObjectName设置为对应的文件夹名称。如果文件夹非空，则需要将文件夹下的所有object删除后才能删除该文件夹。
            ossClient.deleteObject(MemberEnumConfig.backetName, fileDir1);
            // 关闭OSSClient。
            ossClient.shutdown();
        } catch (Exception e) {
            throw new Exception("删除oss文件出错");
        } finally {
            ossClient.shutdown();
        }
        String sql = "delete from icon_infos1 where id='" + id + "'";
        return sqlMapper.delete(sql);
    }

    //删除正式表图片 以及路径下的文件
    @RequestMapping(value = "/delteCancel4", method = RequestMethod.POST)
    @ResponseBody
    public int delteProcess4(String customerId) throws Exception {
        if (ToolUtil.isEmpty(customerId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        //找到文件夹的url
        String selSql = "select id,image_url from icon_infos where customer_id='" + customerId + "'";
        List<IconInfo> infoList = sqlMapper.selectList(selSql, IconInfo.class);
        String httpUrl = infoList.get(0).getImageUrl();
//        String urlName = httpUrl.substring(httpUrl.indexOf("photoScoring") + 13).replace("/", "\\");
//        String pathName = urlName.substring(0, urlName.lastIndexOf("\\"));
//        String pathUrl = "D:\\8068\\apache-tomcat-8.0.30\\webapps\\ROOT\\photoScoring\\" + pathName + "";
//        File file = new File(pathUrl);//文件所在的路径
//        deleteDirectory(file);
        OSSClient ossClient = new OSSClient(MemberEnumConfig.endPoint, MemberEnumConfig.accessKeyId, MemberEnumConfig.accessKeySecret);
        try {
            for (IconInfo iconInfo : infoList) {
                OSSObject object1 = ossClient.getObject(MemberEnumConfig.backetName, "photoScoring/" + iconInfo.getImageUrl().split("photoScoring/")[1]);
                String fileDir1 = object1.getKey();
                // 删除文件。如需删除文件夹，请将ObjectName设置为对应的文件夹名称。如果文件夹非空，则需要将文件夹下的所有object删除后才能删除该文件夹。
                ossClient.deleteObject(MemberEnumConfig.backetName, fileDir1);
            }
            // 关闭OSSClient。
            ossClient.shutdown();
        } catch (Exception e) {
            throw new Exception("删除oss文件出错");
        } finally {
            ossClient.shutdown();
        }
        String sql = "delete from icon_infos1 where customer_id='" + customerId + "'";
        return sqlMapper.delete(sql);
    }

    //删除整组打分影像
    @RequestMapping(value = "/deleteScoringIcons", method = RequestMethod.POST)
    @ResponseBody
    public int deleteScoringIcons(String num) throws Exception {
        String selSql = "select id,image_url from icon_infos where num='" + num + "';";
        List<IconInfo> iconInfoList = sqlMapper.selectList(selSql, IconInfo.class);
//        String httpUrl = iconInfo.getImageUrl();
//        String urlName = httpUrl.substring(httpUrl.indexOf("photoScoring") + 13).replace("/", "\\");
//        String pathName = urlName.substring(0, urlName.lastIndexOf("\\"));
//        String pathUrl = "D:\\8068\\apache-tomcat-8.0.30\\webapps\\ROOT\\photoScoring\\" + pathName + "";
//        File file = new File(pathUrl);//文件所在的路径
//        deleteDirectory(file);
        OSSClient ossClient = new OSSClient(MemberEnumConfig.endPoint, MemberEnumConfig.accessKeyId, MemberEnumConfig.accessKeySecret);
        try {
            for (IconInfo iconInfo : iconInfoList) {
                OSSObject object1 = ossClient.getObject(MemberEnumConfig.backetName, "photoScoring/" + iconInfo.getImageUrl().split("photoScoring/")[1]);
                String fileDir1 = object1.getKey();
                // 删除文件。如需删除文件夹，请将ObjectName设置为对应的文件夹名称。如果文件夹非空，则需要将文件夹下的所有object删除后才能删除该文件夹。
                ossClient.deleteObject(MemberEnumConfig.backetName, fileDir1);
            }
            // 关闭OSSClient。
            ossClient.shutdown();
        } catch (Exception e) {
            throw new Exception("删除oss文件出错");
        } finally {
            ossClient.shutdown();
        }
        String sql = "delete from icon_infos where num='" + num + "'";
        return sqlMapper.delete(sql);
    }

    public static void deleteDirectory(File file) {
        if (file.isFile()) {
            file.delete();//清理文件
        } else {
            File list[] = file.listFiles();
            if (list != null) {
                for (File f : list) {
                    deleteDirectory(f);
                }
                file.delete();//清理目录
            }
        }
    }

    //智能评分
    @RequestMapping("/getIntelligentScoreDetailsList/{num}")
    @ResponseBody
    public Object getUpdateLogList(@PathVariable String num, SearchCaseSelectionIntelligentScoreInfo
            info, HttpServletRequest request) {
        Page<CaseSelectionIntelligentScoreInfo> page = new PageFactory<CaseSelectionIntelligentScoreInfo>().defaultPage();
        try {
            info.setStartIndex(page.getSize() * (page.getCurrent() - 1));
            info.setLimitIndex(page.getSize());
            page.setCurrent(0);
            info.setNum(num);
            List<CaseSelectionIntelligentScoreInfo> list = service.getIntelligentScoreDetailsList(page, info);
            if (list.size() == 0) {
                info.setStartIndex(0);
                list = service.getIntelligentScoreDetailsList(page, info);
            }
            page.setRecords(list);
            page.setTotal(service.getIntelligentScoreDetailsCount(page, info));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return super.packForBT(page);
    }

    /**
     * 医生排班
     *
     * @return
     */
    @RequestMapping(value = "/findDoctorSchedulingList/", method = RequestMethod.POST)
    @ResponseBody
    public List<DoctorSchedulingInfo> findDoctorSchedulingList(String startDate, String endDate, String outpatientName) {
        String getListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                " where (c.name='医生' or c.name='洁牙师') and a.status='1' and b.simplename= '" + outpatientName + "'";
        List<ConsultantInfo> docList = sqlMapper.selectList(getListSql, ConsultantInfo.class); //根据角色用户查询所有医生
        String sql1 = "select id as id,doctor_id as doctorId,status as status ,remarks as remarks,create_time as createTime,update_people as updatePeople" +
                ",update_time as updateTime,the_date as theDate from doctor_scheduling where the_date >='" + startDate + "'and the_date <='" + endDate + "' and outpatient_name ='" + outpatientName + "' ";
        List<DoctorSchedulingInfo> schList = sqlMapper.selectList(sql1, DoctorSchedulingInfo.class); //根据当前日期查询 所有的排班信息
        //循环医生集合,组装每个医生周一至周日的排班情况,默认是正常班,通过查询医生排班表已设置的休息记录给对应医生对应的日期赋值对应的排班状态
        List<DoctorSchedulingInfo> tableList = new ArrayList<DoctorSchedulingInfo>();
        for (ConsultantInfo doc : docList) {//实例化一个医生对应的一周排班实体对象
            DoctorSchedulingInfo docSch = new DoctorSchedulingInfo();
            docSch.setDoctorId(doc.getId());
            docSch.setDoctorName(doc.getDoctor());
            List<String> dateList = DateUtil.getDays(startDate, endDate); //获取起始日期的每天的集合,比方说起点是1号,那么我们就要把1号到7号所有日期都列出来,然后循环排班班是否在对应的日期有休息的排班
            for (int i = 0; i < 7; i++) {
                String curDate = dateList.get(i);
                boolean isSch = false;//默认正常班
                for (DoctorSchedulingInfo sch : schList) { //循环医生排班集合,判断对应日期是否有排班
                    if (sch.getDoctorId().equals(doc.getId()) && sch.getTheDate().equals(curDate) && sch.getStatus().toString().equals("2")) {
                        isSch = true;//如果当前医生对应日期有排班,且状态为2 休息 就退出当前排班循环
                        break;
                    }
                }
                if (isSch) {//如果是排班休息
                    if (i == 0) {///周一
                        docSch.setMondayStatus("2");
                    } else if (i == 1) {///周二
                        docSch.setTuesdayStatus("2");
                    } else if (i == 2) {///周三
                        docSch.setWednesdayStatus("2");
                    } else if (i == 3) {///周四
                        docSch.setThursdayStatus("2");
                    } else if (i == 4) {///周五
                        docSch.setFridayStatus("2");
                    } else if (i == 5) {///周六
                        docSch.setSaturdayStatus("2");
                    } else if (i == 6) {///周日
                        docSch.setSundayStatus("2");
                    }
                }
            }
            tableList.add(docSch); //加入到返回前端集合中
        }
        return tableList;
    }

    /**
     * 修改医生排班信息(点击正常班 休息)
     */
    @RequestMapping(value = "/updateStatus/", method = RequestMethod.POST)
    @ResponseBody
    public int updateDoctorStatus(String doctorName, String doctorId, String docTime, String docStatus) {
        String[] times = docTime.split(",");//适配一个或者多个时间,如果只穿了1个times数组就是一个
        for (String curTime : times) {
            String sql2 = "delete from doctor_scheduling where doctor_id = '" + doctorId + "' and the_date = '" + curTime + "' and outpatient_name ='" + ShiroKit.getUser().getOutpatientName() + "'";
            sqlMapper.delete(sql2);
            String sql = "insert into doctor_scheduling (doctor_id,doctor_name,the_date,status,update_time,update_people,outpatient_name) VALUES ('" + doctorId + "','" + doctorName + "','" + curTime + "','" + docStatus + "','" + DateTimeKit.now() + "','" + ShiroKit.getUser().getAccount() + "','" + ShiroKit.getUser().getOutpatientName() + "')";
            sqlMapper.insert(sql);
        }
        return 1;
    }

    /**
     * 预约视图  医生集合 接口 （起始时间  和  结束时间 ）根据角色用户查询 未指定医生、分诊医生
     */
    @RequestMapping(value = "/getListedDoctor/{timeSlot}")
    @ResponseBody
    public List<ConsultantInfo> getListedDoctor(@PathVariable String timeSlot) {
        String sql = "select 361 as id,'未指定医生' as doctor,61;";
        List<ConsultantInfo> todayDocViewsList = sqlMapper.selectList(sql, ConsultantInfo.class);
        return todayDocViewsList;
    }

    /**
     * 预约视图  医生集合 接口 （起始时间  和  结束时间 ）根据角色用户查询所有医生
     */
    @RequestMapping(value = "/getListed/{timeSlot}")
    @ResponseBody
    public List<ConsultantInfo> getListed(@PathVariable String timeSlot) {
        String startTime = timeSlot.split(",")[0].substring(0, 10);
        String endTime = timeSlot.split(",")[1].substring(0, 10);
        String sql = "select id,doctor from (" +
                " (select a.id as id,a.account as doctor,a.roleid from user a where (a.roleid=" + ShiroKit.getUser().getDentistRoleId() + "" +
                " or a.roleid=" + ShiroKit.getUser().getDoctorRoleId() + ") and a.deptid like CONCAT('%'," + ShiroKit.getUser().getDeptId() + ",',','%') and a.status=1 and a.id" +
                " not in(select b.doctor_id from doctor_scheduling b where " +
                " b.the_date>='" + startTime + "' and b.the_date<='" + endTime + "' and b.status=2 and b.outpatient_name='" + ShiroKit.getUser().getOutpatientName() + "')) " +
                " union all (select " + ShiroKit.getUser().getPublicDoctorRoleId() + " as id,'未指定医生' as doctor,61 from user d limit 0,1)" +
                " ) t  order by roleid,id;";
        List<ConsultantInfo> todayDocViewsList = sqlMapper.selectList(sql, ConsultantInfo.class);
        return todayDocViewsList;
    }

    /**
     * 预约视图  医生集合 接口 （起始时间  和  结束时间 ） 未上班下面有预约患者的医生
     */
    @RequestMapping(value = "/consultRestDoctor/{timeSlot}")
    @ResponseBody
    public List<ConsultantInfo> consultRestDoctor(@PathVariable String timeSlot) {
        String startTime = timeSlot.split(",")[0].substring(0, 10);
        String endTime = timeSlot.split(",")[1].substring(0, 10);
        String sql = "select b.doctor_id as id,b.doctor_name as doctor,count(1) as countNum from doctor_scheduling b " +
                " left join " + ShiroKit.getUser().getCustomer_info() + " a on a.doctor=b.doctor_name " +
                " where b.the_date >='" + startTime + "' and b.the_date <='" + endTime + "' and " +
                " left(a.start_time,10)>='" + startTime + "' and left(a.end_time,10)<='" + endTime + "' and a.arrival_status!='8'" +
                " and b.status=2 and b.outpatient_name='" + ShiroKit.getUser().getOutpatientName() + "' group by b.doctor_id";
        List<ConsultantInfo> todayRestDoctorList = sqlMapper.selectList(sql, ConsultantInfo.class);
        return todayRestDoctorList;
    }

    /**
     * 预约视图  医生集合 接口 （起始时间  和  结束时间 ）根据角色用户查询所有洁牙师
     */
    @RequestMapping(value = "/getJysListed/{timeSlot}")
    @ResponseBody
    public List<ConsultantInfo> getJysListed(@PathVariable String timeSlot) {
        String startTime = timeSlot.split(",")[0].substring(0, 10);
        String endTime = timeSlot.split(",")[1].substring(0, 10);
        String sql = "select a.id as id,a.account as doctor from user a where a.roleid=" + ShiroKit.getUser().getDentistRoleId() + " " +
                " and a.deptid like CONCAT('%'," + ShiroKit.getUser().getDeptId() + ",',','%') and a.status=1 and a.id" +
                " not in(select b.doctor_id from doctor_scheduling b where " +
                " b.the_date>='" + startTime + "' and b.the_date<='" + endTime + "' and b.status=2 and b.outpatient_name='" + ShiroKit.getUser().getOutpatientName() + "')" +
                " union all (select " + ShiroKit.getUser().getPublicDoctorRoleId() + " as id,'未指定医生' as doctor from user d limit 0,1)";
        List<ConsultantInfo> todayJysList = sqlMapper.selectList(sql, ConsultantInfo.class);
        return todayJysList;
    }

    /**
     * 查找数据源
     */
    @RequestMapping(value = "/getDataList/{timeSlot}")
    @ResponseBody
    public List<ConsultantInfo> getDataList(@PathVariable String timeSlot) {
        String startTime = timeSlot.split(",")[0].substring(0, 10);
        String endTime = timeSlot.split(",")[1].substring(0, 10);
        String startTime2 = timeSlot.split(",")[0];
        String endTime2 = timeSlot.split(",")[1];
        String sql1 = "";
        if (startTime.equals(endTime)) {
            sql1 += "left(t.start_time,10) = '" + startTime + "'";
        } else {
            sql1 += "t.start_time >= '" + startTime2 + "' and t.end_time <= '" + endTime2 + "'";
        }
        //根据角色用户查询所有医生
        String sql = " select * from (select t1.id as id,t.customer_name as customerName,customer_status as customerStatus,t.check_status as checkStatus,t.customer_age as customerAge,t.customer_phone as customerPhone,t.medical_record_number as medicalRecordNumber," +
                " ( " +
                " CASE t.customer_sex " +
                " WHEN 1 THEN " +
                "     '男' " +
                " WHEN 2 THEN " +
                "     '女' " +
                " ELSE " +
                "     '未知' " +
                " END " +
                "    ) as sex ,t.customer_sex_head as customerSexHead,t.archiving as archiving ,t.reservations_id as reservationsId,t.yellow_number as yellowNumber," +
                "t.treatment_unit as treatmentUnit,t.account_arrears as accountArrears," +
                "(select count(id) from " + ShiroKit.getUser().getCustomer_info() + " b where t.reservations_id=b.reservations_id and left(start_time,10)=left(now(),10)) as todaySum," +
                "(select count(id) from " + ShiroKit.getUser().getCustomer_info() + " b where t.reservations_id=b.reservations_id and left(start_time,10)>left(now(),10)) as aftersSum," +
                "(select count(id) from " + ShiroKit.getUser().getCustomer_info() + " b where t.reservations_id=b.reservations_id and left(start_time,10)<left(now(),10)) as beforeSum," +
                "t.arrival_status as arrivalStatus,t.arrival_store as arrivalStore ,t.birthday as birthday ," +
                "left(t.create_appointment_time,19) as createAppointmentTime,t.remarks as remarks,t.remarks_reservation as remarksReservation, t.field_tc as fieldTc,t.first_visit_date as firstVisitDate," +
                "t.appointment_pay_service as appointmentPayService ,t.start_time as startTime, t.end_time as endTime,t.doctor,t.id as customerId from " + ShiroKit.getUser().getCustomer_info() + " t " +
                "left join user t1 on t.doctor=t1.account where " + sql1 + " and t.arrival_status!=8 order by t.create_appointment_time) t2 ";
        List<ConsultantInfo> DataList = sqlMapper.selectList(sql, ConsultantInfo.class);
        return DataList;
    }

    /**
     * 当前登录医生查找数据源
     */
    @RequestMapping(value = "/getDataListByDoctor/{timeSlot}")
    @ResponseBody
    public List<ConsultantInfo> getDataListByDoctor(@PathVariable String timeSlot) {
        String startTime = timeSlot.split(",")[0].substring(0, 11);
        String doctor = timeSlot.split(",")[2];
        //根据角色用户查询所有医生
        String sql = " select t1.id as id,t.customer_name as customerName,t.customer_age as customerAge,customer_status as customerStatus,t.customer_phone as customerPhone,t.medical_record_number as medicalRecordNumber," +
                " ( " +
                " CASE t.customer_sex " +
                " WHEN 1 THEN " +
                "     '男' " +
                " WHEN 2 THEN " +
                "     '女' " +
                " ELSE " +
                "     '未知' " +
                " END " +
                "    ) as sex,t.archiving as archiving ,t.reservations_id as reservationsId,t.arrival_status as arrivalStatus ," +
                " t.arrival_store as arrivalStore ,t.birthday as birthday ,left(t.create_appointment_time,19) as createAppointmentTime," +
                " t.field_tc as fieldTc,t.first_visit_date as firstVisitDate,t.appointment_pay_service as appointmentPayService ," +
                " t.start_time as startTime, t.end_time as endTime,t.doctor,t.id as customerId,t.account_arrears as accountarrears " +
                " from " + ShiroKit.getUser().getCustomer_info() + " t " +
                " left join user t1 on t.doctor=t1.account where left(t.start_time,10) = '" + startTime.substring(0, 10) + "' " +
                " and doctor='" + doctor + "' and t.arrival_status!=8 ";
        List<ConsultantInfo> DataList = sqlMapper.selectList(sql, ConsultantInfo.class);
        return DataList;
    }

    /**
     * 获取医生当前的休息状态
     */
    @RequestMapping(value = "/getDoctorStatus", method = RequestMethod.POST)
    @ResponseBody
    public String getDoctorStatus(String doctor, String value) throws Exception {
        String sql = "select t.status from doctor_scheduling t where t.doctor_name='" + doctor + "' and left(t.the_date,10)='" + value.substring(0, 10) + "' and t.outpatient_name='" + ShiroKit.getUser().getOutpatientName() + "' limit 1";
        DoctorLookedInfo doctorLookedInfo = sqlMapper.selectOne(sql, DoctorLookedInfo.class);
        if (doctorLookedInfo == null) {
            return "1";
        } else {
            return doctorLookedInfo.getStatus();
        }
    }


    /**
     * 获得此医生本周休息的日期
     */
    @RequestMapping(value = "/getRestingState/{timeSlot}", method = RequestMethod.POST)
    @ResponseBody
    public List<DoctorSchedulingInfo> getRestingState(@PathVariable String timeSlot, Model model) {
        String startTime = timeSlot.split(",")[0];
        String endTime = timeSlot.split(",")[1];
        String doctorId = timeSlot.split(",")[2];
        String sql1 = " select t.doctor_id as doctorId ,t1.account as doctorName ,t.the_date as theDate" +
                " from doctor_scheduling t  left join user t1 on t.doctor_id=t1.id " +
                " where t.doctor_id='" + doctorId + "' and t.status=2 " +
                " and t.the_date between '" + startTime + "' and '" + endTime + "' and t.outpatient_name='" + ShiroKit.getUser().getOutpatientName() + "' ";
        List<DoctorSchedulingInfo> schedulingInfo = sqlMapper.selectList(sql1, DoctorSchedulingInfo.class);
        return schedulingInfo;
    }

    /**
     * 当前个人医生视图查找数据源  传开始时间和结束时间(一周时间)  医生ID
     */
    @RequestMapping(value = "/getDataDoctor/{timeSlot}")
    @ResponseBody
    public List<ConsultantInfo> getDataDoctor(@PathVariable String timeSlot) {
        String startTime = timeSlot.split(",")[0].substring(0, 11);
        String endTime = timeSlot.split(",")[1].substring(0, 11);
        String doctorId = timeSlot.split(",")[2];
        String startTime2 = timeSlot.split(",")[0];
        String endTime2 = timeSlot.split(",")[1];
        String sql1 = "";
        if (startTime.equals(endTime)) {
            sql1 += "t.start_time  like CONCAT('%" + startTime + "%')";
        } else {
            sql1 += "t.start_time >=  '" + startTime2 + "' and t.end_time <= '" + endTime2 + "'";
        }
        String sql2 = "select id,account from user where id ='" + doctorId + "' limit 1";
        User user = sqlMapper.selectOne(sql2, User.class);
        String sql = " select * from (select t1.id as id,t.customer_name as customerName,customer_status as customerStatus,t.customer_age as customerAge,t.customer_phone as customerPhone,t.medical_record_number as medicalRecordNumber," +
                "     ( " +
                " CASE t.customer_sex " +
                " WHEN 1 THEN " +
                "     '男' " +
                " WHEN 2 THEN " +
                "     '女' " +
                " ELSE " +
                "     '未知' " +
                " END " +
                "    ) as sex ,t.archiving as archiving ,t.reservations_id as reservationsId,t.yellow_number as yellowNumber," +
                "t.treatment_unit as treatmentUnit,t.account_arrears as accountArrears," +
                "(select count(id) from " + ShiroKit.getUser().getCustomer_info() + " b where t.reservations_id=b.reservations_id and left(start_time,10)=left(now(),10)) as todaySum," +
                "(select count(id) from " + ShiroKit.getUser().getCustomer_info() + " b where t.reservations_id=b.reservations_id and left(start_time,10)>left(now(),10)) as aftersSum," +
                "(select count(id) from " + ShiroKit.getUser().getCustomer_info() + " b where t.reservations_id=b.reservations_id and left(start_time,10)<left(now(),10)) as beforeSum," +
                "t.arrival_status as arrivalStatus,t.arrival_store as arrivalStore ,t.birthday as birthday ," +
                "left(t.create_appointment_time,19) as createAppointmentTime,t.remarks as remarks,t.remarks_reservation as remarksReservation, t.field_tc as fieldTc,t.first_visit_date as firstVisitDate," +
                "t.appointment_pay_service as appointmentPayService ,t.start_time as startTime, t.end_time as endTime,t.doctor,t.id as customerId " +
                " from " + ShiroKit.getUser().getCustomer_info() + " t " +
                " left join user t1 on t.doctor=t1.account where " + sql1 + " " +
                " and t.arrival_status!=8 and doctor='" + user.getAccount() + "' order by t.create_appointment_time) t2 ";
        List<ConsultantInfo> DataWeekList = sqlMapper.selectList(sql, ConsultantInfo.class);
        return DataWeekList;
    }

    /**
     * 当前个人医生视图查找数据源  传开始时间和结束时间(一天时间)  医生ID
     */
    @RequestMapping(value = "/getOneDoctor/{timeSlot}")
    @ResponseBody
    public List<ConsultantInfo> getOneDoctor(@PathVariable String timeSlot) {
        String startTime = timeSlot.split(",")[0].substring(0, 11);
        String endTime = timeSlot.split(",")[1].substring(0, 11);
        String doctorId = timeSlot.split(",")[2];
        String sql1 = "";
        if (startTime.equals(endTime)) {
            sql1 += "t.start_time  like CONCAT('%" + startTime + "%')";
        }
        String sql2 = "select id,account from user where id ='" + doctorId + "' limit 1";
        User user = sqlMapper.selectOne(sql2, User.class);
        String sql = " select t1.id as id,t.customer_name as customerName,t.customer_age as customerAge,t.customer_phone as customerPhone,t.medical_record_number as medicalRecordNumber," +
                " ( " +
                " CASE t.customer_sex " +
                " WHEN 1 THEN " +
                "     '男' " +
                " WHEN 2 THEN " +
                "     '女' " +
                " ELSE " +
                "     '未知' " +
                " END " +
                "    ) as sex,t.archiving as archiving ,t.arrival_status as arrivalStatus ,t.arrival_store as arrivalStore ,t.birthday as birthday ," +
                " left(t.create_appointment_time,19) as createAppointmentTime,t.field_tc as fieldTc,t.first_visit_date as firstVisitDate," +
                " t.appointment_pay_service as appointmentPayService ,t.start_time as startTime, t.end_time as endTime,t.doctor,t.id as customerId from " + ShiroKit.getUser().getCustomer_info() + " t " +
                " left join user t1 on t.doctor=t1.account where " + sql1 + " and doctor='" + user.getAccount() + "'";
        List<ConsultantInfo> DataOneList = sqlMapper.selectList(sql, ConsultantInfo.class);
        return DataOneList;
    }

    /**
     * 查询预约视图 看诊项目集合
     */
    @RequestMapping(value = "/getListInfo", method = RequestMethod.POST)
    @ResponseBody
    public List<DiagnoseProjectInfo> getDiagnoseInfo(String projectCategory) throws Exception {
        String param = "";
        if (StringUtils.isNotBlank(projectCategory)) {
            String categoryProjectNameList = projectCategory + "projectNameList";
            if (ShiroKit.getSessionAttr(categoryProjectNameList) == null) {
                param += " and project_category = '" + projectCategory + "' ";
                String selectSql = "select id,add_name as addName,project_category as projectCategory,project_name as projectName ," +
                        "create_time as createTime,update_time as updateTime from diagnose_project_info where 1=1" + param + " ";
                ShiroKit.setSessionAttr(categoryProjectNameList, sqlMapper.selectList(selectSql));
                return ShiroKit.getSessionAttr(categoryProjectNameList);
            } else {
                return ShiroKit.getSessionAttr(categoryProjectNameList);
            }
        } else {
            if (ShiroKit.getSessionAttr("projectNameList") == null) {
                String selectSql = "select id,add_name as addName,project_category as projectCategory,project_name as projectName ," +
                        "create_time as createTime,update_time as updateTime from diagnose_project_info;";
                ShiroKit.setSessionAttr("projectNameList", sqlMapper.selectList(selectSql));
                return ShiroKit.getSessionAttr("projectNameList");
            } else {
                return ShiroKit.getSessionAttr("projectNameList");
            }
        }
    }

    /**
     * 查询加工单位集合
     */
    @RequestMapping(value = "/getProcessInfo", method = RequestMethod.POST)
    @ResponseBody
    public List<ProcessUnitInfo> getProcessInfo() throws Exception {
        if (ShiroKit.getSessionAttr("processList") == null) {
            String selectSql = "select id,add_name as addName,process_unit as processUnit,create_time as createTime from processing_unit;";
            ShiroKit.setSessionAttr("processList", sqlMapper.selectList(selectSql));
            return ShiroKit.getSessionAttr("processList");
        } else {
            return ShiroKit.getSessionAttr("processList");
        }
    }

    /**
     * 查询取件人集合
     */
    @RequestMapping(value = "/getPickerInfo", method = RequestMethod.POST)
    @ResponseBody
    public List<PickerInfo> getPickerInfo() throws Exception {
        if (ShiroKit.getSessionAttr("pickerList") == null) {
            String selectSql = "select id,add_name as addName,picker as picker,create_time as createTime from picker;";
            ShiroKit.setSessionAttr("pickerList", sqlMapper.selectList(selectSql));
            return ShiroKit.getSessionAttr("pickerList");
        } else {
            return ShiroKit.getSessionAttr("pickerList");
        }
    }

    /**
     * 跳转到上传正畸初诊
     */
    @RequestMapping(value = "/orthodonticsFirst/{rc}")
    public String orthodonticsFirst(@PathVariable String rc, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        if (ShiroKit.getUser().getDoctorInfoList() == null) {
            String doctorListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + ShiroKit.getUser().getAbbreviation() + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            List<DoctorInfo> doctorInfoList=sqlMapper.selectList(doctorListSql,DoctorInfo.class);
            ShiroKit.getUser().setDoctorInfoList(doctorInfoList);
        }
        model.addAttribute("doctorList", ShiroKit.getUser().getDoctorInfoList());
        String reservationsId = rc.split(",")[0];
        String customerName = rc.split(",")[1];
        String deletsql = "delete from root_orthodontics_imgs_info where reservations_id='" + reservationsId + "' and status=0 and create_name='" + ShiroKit.getUser().getAccount() + "';";
        sqlMapper.delete(deletsql);
        String arrTimeSql = "select id,add_time as addTime,DATE_FORMAT(now(),'%Y%m%d%k%i%S') as randomNumber from distinction_customer_status where reservations_id='" + reservationsId + "' and add_time is not null and status=1  order by add_time limit 1;";
        CustomerInfo info = sqlMapper.selectOne(arrTimeSql, CustomerInfo.class);
        model.addAttribute("num", info.getRandomNumber());
        model.addAttribute("arrivalTime", info.getAddTime().substring(0, 10));
        model.addAttribute("customerName", customerName);
        model.addAttribute("userName", ShiroKit.getUser().getAccount());
        model.addAttribute("reservationsId", reservationsId);
        return PREFIX + "doctor_orthodonticsFirst.html";
    }

    /**
     * 上传正畸初诊图片回显
     */
    @RequestMapping(value = "/orthodonticsDisplay/{ids}")
    public String orthodonticsDisplay(@PathVariable String ids, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        String num = ids.split(",")[0];
        String reservationsId = ids.split(",")[1];
        String idsType = ids.split(",")[2];
        String doctor = ids.split(",")[3];
        String sql = "select * from root_orthodontics_info a left join root_orthodontics_imgs_info b on a.num=b.num" +
                " where a.num='" + num + "' and a.reservations_id='" + reservationsId + "'";
        String sql1 = "select * from root_orthodontics_info a where a.num='" + num + "' and a.reservations_id='" + reservationsId + "' limit 1";
        RootImageInfo info = sqlMapper.selectOne(sql1, RootImageInfo.class);
        List<RootImageInfo> infoList = sqlMapper.selectList(sql, RootImageInfo.class);
        if (ShiroKit.getUser().getDoctorInfoList() == null) {
            String doctorListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + ShiroKit.getUser().getAbbreviation() + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            List<DoctorInfo> doctorInfoList=sqlMapper.selectList(doctorListSql,DoctorInfo.class);
            ShiroKit.getUser().setDoctorInfoList(doctorInfoList);
        }
        model.addAttribute("doctorList", ShiroKit.getUser().getDoctorInfoList());
        model.addAttribute("infoList", infoList);
        model.addAttribute("doctor", doctor);
        model.addAttribute("num", num);
        model.addAttribute("info", info);
        model.addAttribute("userName", ShiroKit.getUser().getAccount());
        model.addAttribute("reservationsId", reservationsId);
        if ("1".equals(idsType)) {
            return PREFIX + "doctor_orthodonticsDisplay1.html";
        } else {
            return PREFIX + "doctor_orthodonticsDisplay.html";
        }
    }

    /**
     * 上传正畸初诊图片回显
     */
    @RequestMapping(value = "/orthodonticsDisplay1/{ids}")
    public String orthodonticsDisplay1(@PathVariable String ids, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        String num = ids.split(",")[0];
        String reservationsId = ids.split(",")[1];
        String idsType = ids.split(",")[2];
        String doctor = ids.split(",")[3];
        String sql = "select * from root_orthodontics_info a left join root_orthodontics_imgs_info b on a.num=b.num" +
                " where a.num='" + num + "' and a.reservations_id='" + reservationsId + "'";
        String sql1 = "select * from root_orthodontics_info a where a.num='" + num + "' and a.reservations_id='" + reservationsId + "' limit 1";
        RootImageInfo info = sqlMapper.selectOne(sql1, RootImageInfo.class);
        List<RootImageInfo> infoList = sqlMapper.selectList(sql, RootImageInfo.class);
        if (ShiroKit.getUser().getDoctorInfoList() == null) {
            String doctorListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + ShiroKit.getUser().getAbbreviation() + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            List<DoctorInfo> doctorInfoList=sqlMapper.selectList(doctorListSql,DoctorInfo.class);
            ShiroKit.getUser().setDoctorInfoList(doctorInfoList);
        }
        model.addAttribute("doctorList", ShiroKit.getUser().getDoctorInfoList());
        model.addAttribute("infoList", infoList);
        model.addAttribute("doctor", doctor);
        model.addAttribute("num", num);
        model.addAttribute("info", info);
        model.addAttribute("userName", ShiroKit.getUser().getAccount());
        model.addAttribute("reservationsId", reservationsId);
        return PREFIX + "doctor_orthodonticsDisplay2.html";
    }

    /**
     * 上传正畸完成图片回显
     */
    @RequestMapping(value = "/orthodonticComplexDisplay/{ids}")
    public String orthodonticComplexDisplay(@PathVariable String ids, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        String num = ids.split(",")[0];
        String reservationsId = ids.split(",")[1];
        String idsType = ids.split(",")[2];
        String doctor = ids.split(",")[3];
        String sql = "select * from root_orthodontics_info a left join root_orthodontics_imgs_info b on a.num=b.num" +
                " where a.num='" + num + "' and a.reservations_id='" + reservationsId + "'";
        String sql1 = "select * from root_orthodontics_info a where a.num='" + num + "' and a.reservations_id='" + reservationsId + "' limit 1";
        RootImageInfo info = sqlMapper.selectOne(sql1, RootImageInfo.class);
        List<RootImageInfo> infoList = sqlMapper.selectList(sql, RootImageInfo.class);
        if (ShiroKit.getUser().getDoctorInfoList() == null) {
            String doctorListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + ShiroKit.getUser().getAbbreviation() + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            List<DoctorInfo> doctorInfoList=sqlMapper.selectList(doctorListSql,DoctorInfo.class);
            ShiroKit.getUser().setDoctorInfoList(doctorInfoList);
        }
        model.addAttribute("doctorList", ShiroKit.getUser().getDoctorInfoList());
        model.addAttribute("infoList", infoList);
        model.addAttribute("reservationsId", reservationsId);
        model.addAttribute("num", num);
        model.addAttribute("doctor", doctor);
        model.addAttribute("info", info);
        model.addAttribute("userName", ShiroKit.getUser().getAccount());
        model.addAttribute("reservationsId", reservationsId);
        if ("1".equals(idsType)) {
            return PREFIX + "doctor_orthodonticComplexDisplay1.html";
        } else {
            return PREFIX + "doctor_orthodonticComplexDisplay.html";
        }
    }

    /**
     * 跳转到上传正畸复诊
     */
    @RequestMapping(value = "/orthodonticsMiddle/{ids}")
    public String orthodonticsMiddle(@PathVariable String ids, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        String num = ids.split(",")[0];
        String reservationsId = ids.split(",")[1];
        String sql = "select * from root_orthodontics_info a left join root_orthodontics_imgs_info b on a.num=b.num" +
                " where a.num='" + num + "' and a.reservations_id='" + reservationsId + "'";
        List<RootImageInfo> infoList = sqlMapper.selectList(sql, RootImageInfo.class);
        model.addAttribute("infoList", infoList);
        model.addAttribute("num", num);
        model.addAttribute("reservationsId", reservationsId);
        return PREFIX + "doctor_orthodonticsMiddle.html";
    }

    /**
     * 跳转到上传正畸复诊
     */
    @RequestMapping(value = "/orthodonticsComplex/{ids}")
    public String orthodonticsComplex(@PathVariable String ids, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        String num = ids.split(",")[0];
        String reservationsId = ids.split(",")[1];
        if (ShiroKit.getUser().getDoctorInfoList() == null) {
            String doctorListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + ShiroKit.getUser().getAbbreviation() + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            List<DoctorInfo> doctorInfoList=sqlMapper.selectList(doctorListSql,DoctorInfo.class);
            ShiroKit.getUser().setDoctorInfoList(doctorInfoList);
        }
        model.addAttribute("doctorList", ShiroKit.getUser().getDoctorInfoList());
        String deletsql = "delete from root_orthodontics_imgs_info where reservations_id='" + reservationsId + "' and status=0 and create_name='" + ShiroKit.getUser().getAccount() + "';";
        sqlMapper.delete(deletsql);
        if (ShiroKit.getUser().getDoctorInfoList() == null) {
            String doctorListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + ShiroKit.getUser().getAbbreviation() + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            List<DoctorInfo> doctorInfoList=sqlMapper.selectList(doctorListSql,DoctorInfo.class);
            ShiroKit.getUser().setDoctorInfoList(doctorInfoList);
        }
        model.addAttribute("doctorList", ShiroKit.getUser().getDoctorInfoList());
        model.addAttribute("num", num);
        model.addAttribute("userName", ShiroKit.getUser().getAccount());
        model.addAttribute("reservationsId", reservationsId);
        return PREFIX + "doctor_orthodonticsComplex.html";
    }

    /**
     * 跳转到上传根管
     */
    @RequestMapping(value = "/rootCanalScore/{rc}")
    public String rootCanalScore(@PathVariable String rc, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        if (ShiroKit.getUser().getDoctorInfoList() == null) {
            String doctorListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + ShiroKit.getUser().getAbbreviation() + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            List<DoctorInfo> doctorInfoList=sqlMapper.selectList(doctorListSql,DoctorInfo.class);
            ShiroKit.getUser().setDoctorInfoList(doctorInfoList);
        }
        model.addAttribute("doctorList", ShiroKit.getUser().getDoctorInfoList());
        String reservationsId = rc.split(",")[0];
        String customerName = rc.split(",")[1];
        String randomNumber = "select DATE_FORMAT(now(),'%Y%m%d%k%i%S') as randomNumber from dual";
        DaulInfo infos = sqlMapper.selectOne(randomNumber, DaulInfo.class);
        String deletsql = "delete from root_canal_imgs_info where reservations_id='" + reservationsId + "' and status=0 and create_name='" + ShiroKit.getUser().getAccount() + "';";
        sqlMapper.delete(deletsql);
        model.addAttribute("num", infos.getRandomNumber());
        model.addAttribute("reservationsId", reservationsId);
        model.addAttribute("customerName", customerName);
        model.addAttribute("userName", ShiroKit.getUser().getAccount());
        return PREFIX + "doctor_rootCanalScore.html";
    }

    /**
     * 跳转到上传根管图片回显
     */
    @RequestMapping(value = "/rootCanalScoreDisplay/{ids}")
    public String rootCanalScoreDisplay(@PathVariable String ids, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        if (ShiroKit.getUser().getDoctorInfoList() == null) {
            String doctorListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + ShiroKit.getUser().getAbbreviation() + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            List<DoctorInfo> doctorInfoList=sqlMapper.selectList(doctorListSql,DoctorInfo.class);
            ShiroKit.getUser().setDoctorInfoList(doctorInfoList);
        }
        model.addAttribute("doctorList", ShiroKit.getUser().getDoctorInfoList());
        String num = ids.split(",")[0];
        String reservationsId = ids.split(",")[1];
        String idsType = ids.split(",")[2];
        String sql1 = "select * from root_canal_info a where a.num='" + num + "' and a.reservations_id='" + reservationsId + "' limit 1";
        RootImageInfo info = sqlMapper.selectOne(sql1, RootImageInfo.class);
        String sql = "select * from root_canal_info a left join root_canal_imgs_info b on a.num=b.num" +
                " where a.num='" + num + "' and a.reservations_id='" + reservationsId + "'";
        List<RootImageInfo> infoList = sqlMapper.selectList(sql, RootImageInfo.class);
        model.addAttribute("infoList", infoList);
        model.addAttribute("num", num);
        model.addAttribute("info", info);
        model.addAttribute("reservationsId", reservationsId);
        model.addAttribute("userName", ShiroKit.getUser().getAccount());
        if ("1".equals(idsType)) {
            // 根管暂存
            return PREFIX + "doctor_rootCanalScoreDisplay1.html";
        } else {
            // 根管提交
            return PREFIX + "doctor_rootCanalScoreDisplay.html";
        }
    }

    /**
     * 跳转到上传洁牙前
     */
    @RequestMapping(value = "/uploadScalingFirst/{rc}")
    public String uploadScalingFirst(@PathVariable String rc, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        if (ShiroKit.getUser().getDoctorInfoList() == null) {
            String doctorListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + ShiroKit.getUser().getAbbreviation() + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            List<DoctorInfo> doctorInfoList=sqlMapper.selectList(doctorListSql,DoctorInfo.class);
            ShiroKit.getUser().setDoctorInfoList(doctorInfoList);
        }
        model.addAttribute("doctorList", ShiroKit.getUser().getDoctorInfoList());
        String reservationsId = rc.split(",")[0];
        String customerName = rc.split(",")[1];
        String randomNumber = "select DATE_FORMAT(now(),'%Y%m%d%k%i%S') as randomNumber from dual";
        DaulInfo infos = sqlMapper.selectOne(randomNumber, DaulInfo.class);
        String deletsql = "delete from root_scaling_imgs_info where reservations_id='" + reservationsId + "' and status=0 and create_name='" + ShiroKit.getUser().getAccount() + "';";
        sqlMapper.delete(deletsql);
        model.addAttribute("num", infos.getRandomNumber());
        model.addAttribute("customerName", customerName);
        model.addAttribute("userName", ShiroKit.getUser().getAccount());
        return PREFIX + "doctor_uploadScalingFirst.html";
    }

    /**
     * 上传洁牙术前图片回显
     */
    @RequestMapping(value = "/uploadScalingDisplay/{ids}")
    public String uploadScalingDisplay(@PathVariable String ids, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        String num = ids.split(",")[0];
        String reservationsId = ids.split(",")[1];
        String sql1 = "select * from root_scaling_info a where a.num='" + num + "' and a.reservations_id='" + reservationsId + "' limit 1";
        RootImageInfo info = sqlMapper.selectOne(sql1, RootImageInfo.class);
        String sql = "select * from root_scaling_info a left join root_scaling_imgs_info b on a.num=b.num" +
                " where a.num='" + num + "' and a.reservations_id='" + reservationsId + "'";
        List<RootImageInfo> infoList = sqlMapper.selectList(sql, RootImageInfo.class);
        if (ShiroKit.getUser().getDoctorInfoList() == null) {
            String doctorListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + ShiroKit.getUser().getAbbreviation() + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            List<DoctorInfo> doctorInfoList=sqlMapper.selectList(doctorListSql,DoctorInfo.class);
            ShiroKit.getUser().setDoctorInfoList(doctorInfoList);
        }
        model.addAttribute("doctorList", ShiroKit.getUser().getDoctorInfoList());
        model.addAttribute("userName", ShiroKit.getUser().getAccount());
        model.addAttribute("infoList", infoList);
        model.addAttribute("num", num);
        model.addAttribute("info", info);
        model.addAttribute("reservationsId", reservationsId);
        return PREFIX + "doctor_uploadScalingDisplay.html";
    }

    /**
     * 上传洁牙术后图片回显  质量检测
     */
    @RequestMapping(value = "/qualityScalingDisplay/{ids}")
    public String qualityScalingDisplay(@PathVariable String ids, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        String num = ids.split(",")[0];
        String reservationsId = ids.split(",")[1];
        String idsType = ids.split(",")[2];
        String sql1 = "select * from root_scaling_info a where a.num='" + num + "' and a.reservations_id='" + reservationsId + "' limit 1";
        RootImageInfo info = sqlMapper.selectOne(sql1, RootImageInfo.class);
        String sql = "select * from root_scaling_info a left join root_scaling_imgs_info b on a.num=b.num" +
                " where a.num='" + num + "' and a.reservations_id='" + reservationsId + "' and b.status=1 ";
        List<RootImageInfo> infoList = sqlMapper.selectList(sql, RootImageInfo.class);
        if (ShiroKit.getUser().getDoctorInfoList() == null) {
            String doctorListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + ShiroKit.getUser().getAbbreviation() + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            List<DoctorInfo> doctorInfoList=sqlMapper.selectList(doctorListSql,DoctorInfo.class);
            ShiroKit.getUser().setDoctorInfoList(doctorInfoList);
        }
        model.addAttribute("doctorList", ShiroKit.getUser().getDoctorInfoList());
        model.addAttribute("userName", ShiroKit.getUser().getAccount());
        model.addAttribute("infoList", infoList);
        model.addAttribute("num", num);
        model.addAttribute("info", info);
        model.addAttribute("reservationsId", reservationsId);
        if ("1".equals(idsType)) {
            // 洁牙术前
            return PREFIX + "quality_uploadScalingDisplay1.html";
        } else {
            // 洁牙术后
            return PREFIX + "quality_uploadScalingDisplay.html";
        }
    }

    /**
     * 跳转到上传洁牙后
     */
    @RequestMapping(value = "/uploadScalingComplex/{ids}")
    public String uploadScalingComplex(@PathVariable String ids, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        String num = ids.split(",")[0];
        String reservationsId = ids.split(",")[1];
        String deletsql = "delete from root_scaling_imgs_info where reservations_id='" + reservationsId + "' and status=0 and create_name='" + ShiroKit.getUser().getAccount() + "';";
        sqlMapper.delete(deletsql);
        if (ShiroKit.getUser().getDoctorInfoList() == null) {
            String doctorListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + ShiroKit.getUser().getAbbreviation() + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            List<DoctorInfo> doctorInfoList=sqlMapper.selectList(doctorListSql,DoctorInfo.class);
            ShiroKit.getUser().setDoctorInfoList(doctorInfoList);
        }
        model.addAttribute("doctorList", ShiroKit.getUser().getDoctorInfoList());
        model.addAttribute("userName", ShiroKit.getUser().getAccount());
        model.addAttribute("num", num);
        model.addAttribute("reservationsId", reservationsId);
        return PREFIX + "doctor_uploadScalingComplex.html";
    }

    /**
     * 跳转到上传牙周术前
     */
    @RequestMapping(value = "/uploadPeriodontalFirst/{rc}")
    public String uploadPeriodontalFirst(@PathVariable String rc, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        if (ShiroKit.getUser().getDoctorInfoList() == null) {
            String doctorListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + ShiroKit.getUser().getAbbreviation() + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            List<DoctorInfo> doctorInfoList=sqlMapper.selectList(doctorListSql,DoctorInfo.class);
            ShiroKit.getUser().setDoctorInfoList(doctorInfoList);
        }
        model.addAttribute("doctorList", ShiroKit.getUser().getDoctorInfoList());
        String reservationsId = rc.split(",")[0];
        String customerName = rc.split(",")[1];
        String randomNumber = "select DATE_FORMAT(now(),'%Y%m%d%k%i%S') as randomNumber from dual";
        DaulInfo infos = sqlMapper.selectOne(randomNumber, DaulInfo.class);
        String deletsql = "delete from root_periodontal_imgs_info where reservations_id='" + reservationsId + "' and status=0 and create_name='" + ShiroKit.getUser().getAccount() + "';";
        sqlMapper.delete(deletsql);
        model.addAttribute("num", infos.getRandomNumber());
        model.addAttribute("customerName", customerName);
        model.addAttribute("userName", ShiroKit.getUser().getAccount());
        return PREFIX + "doctor_uploadPeriodontalFirst.html";
    }

    /**
     * 上传牙周术前图片回显
     */
    @RequestMapping(value = "/uploadPeriodontalDisplay/{ids}")
    public String uploadPeriodontalDisplay(@PathVariable String ids, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        String num = ids.split(",")[0];
        String reservationsId = ids.split(",")[1];
        String sql1 = "select * from root_periodontal_info a where a.num='" + num + "' and a.reservations_id='" + reservationsId + "' limit 1";
        RootImageInfo info = sqlMapper.selectOne(sql1, RootImageInfo.class);
        String sql = "select * from root_periodontal_info a left join root_periodontal_imgs_info b on a.num=b.num" +
                " where a.num='" + num + "' and a.reservations_id='" + reservationsId + "'";
        List<RootImageInfo> infoList = sqlMapper.selectList(sql, RootImageInfo.class);
        if (ShiroKit.getUser().getDoctorInfoList() == null) {
            String doctorListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + ShiroKit.getUser().getAbbreviation() + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            List<DoctorInfo> doctorInfoList=sqlMapper.selectList(doctorListSql,DoctorInfo.class);
            ShiroKit.getUser().setDoctorInfoList(doctorInfoList);
        }
        model.addAttribute("doctorList", ShiroKit.getUser().getDoctorInfoList());
        model.addAttribute("userName", ShiroKit.getUser().getAccount());
        model.addAttribute("infoList", infoList);
        model.addAttribute("num", num);
        model.addAttribute("info", info);
        model.addAttribute("reservationsId", reservationsId);
        return PREFIX + "doctor_uploadPeriodontalDisplay.html";
    }

    /**
     * 上传牙周术  后  图片回显  质量检测
     */
    @RequestMapping(value = "/qualityPeriodontalDisplay/{ids}")
    public String qualityPeriodontalDisplay(@PathVariable String ids, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        String num = ids.split(",")[0];
        String reservationsId = ids.split(",")[1];
        String idsType = ids.split(",")[2];
        String sql1 = "select * from root_periodontal_info a where a.num='" + num + "' and a.reservations_id='" + reservationsId + "' limit 1";
        RootImageInfo info = sqlMapper.selectOne(sql1, RootImageInfo.class);
        String sql = "select * from root_periodontal_info a left join root_periodontal_imgs_info b on a.num=b.num" +
                " where a.num='" + num + "' and a.reservations_id='" + reservationsId + "' and b.status=1";
        List<RootImageInfo> infoList = sqlMapper.selectList(sql, RootImageInfo.class);
        if (ShiroKit.getUser().getDoctorInfoList() == null) {
            String doctorListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + ShiroKit.getUser().getAbbreviation() + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            List<DoctorInfo> doctorInfoList=sqlMapper.selectList(doctorListSql,DoctorInfo.class);
            ShiroKit.getUser().setDoctorInfoList(doctorInfoList);
        }
        model.addAttribute("doctorList", ShiroKit.getUser().getDoctorInfoList());
        model.addAttribute("userName", ShiroKit.getUser().getAccount());
        model.addAttribute("infoList", infoList);
        model.addAttribute("num", num);
        model.addAttribute("info", info);
        model.addAttribute("reservationsId", reservationsId);
        if ("1".equals(idsType)) {
            // 洁牙术前
            return PREFIX + "quality_uploadPeriodontalDisplay1.html";
        } else {
            // 洁牙术后
            return PREFIX + "quality_uploadPeriodontalDisplay.html";
        }

    }

    /**
     * 跳转到上传牙周术后
     */
    @RequestMapping(value = "/uploadPeriodontalComplex/{ids}")
    public String uploadPeriodontalComplex(@PathVariable String ids, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        String num = ids.split(",")[0];
        String reservationsId = ids.split(",")[1];
        String deletsql = "delete from root_periodontal_imgs_info where reservations_id='" + reservationsId + "' and status=0 and create_name='" + ShiroKit.getUser().getAccount() + "';";
        sqlMapper.delete(deletsql);
        if (ShiroKit.getUser().getDoctorInfoList() == null) {
            String doctorListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + ShiroKit.getUser().getAbbreviation() + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            List<DoctorInfo> doctorInfoList=sqlMapper.selectList(doctorListSql,DoctorInfo.class);
            ShiroKit.getUser().setDoctorInfoList(doctorInfoList);
        }
        model.addAttribute("doctorList", ShiroKit.getUser().getDoctorInfoList());
        model.addAttribute("userName", ShiroKit.getUser().getAccount());
        model.addAttribute("num", num);
        model.addAttribute("reservationsId", reservationsId);
        return PREFIX + "doctor_uploadPeriodontalComplex.html";
    }

    /**
     * 跳转到上传种植术前,术中,术后
     */
    @RequestMapping(value = "/uploadPlantScoreFirst/{rc}")
    public String uploadPlantScoreFirst(@PathVariable String rc, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        if (ShiroKit.getUser().getDoctorInfoList() == null) {
            String doctorListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + ShiroKit.getUser().getAbbreviation() + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            List<DoctorInfo> doctorInfoList=sqlMapper.selectList(doctorListSql,DoctorInfo.class);
            ShiroKit.getUser().setDoctorInfoList(doctorInfoList);
        }
        model.addAttribute("doctorList", ShiroKit.getUser().getDoctorInfoList());
        String reservationsId = rc.split(",")[0];
        String customerName = rc.split(",")[1];
        String randomNumber = "select DATE_FORMAT(now(),'%Y%m%d%k%i%S') as randomNumber from dual";
        DaulInfo infos = sqlMapper.selectOne(randomNumber, DaulInfo.class);
        String deletsql = "delete from root_plant_imgs_info where reservations_id='" + reservationsId + "' and status=0 and create_name='" + ShiroKit.getUser().getAccount() + "';";
        sqlMapper.delete(deletsql);
        model.addAttribute("num", infos.getRandomNumber());
        model.addAttribute("customerName", customerName);
        model.addAttribute("userName", ShiroKit.getUser().getAccount());
        return PREFIX + "doctor_uploadPlantScoreFirst.html";
    }

    /**
     * 跳转到上传种植图片回显
     */
    @RequestMapping(value = "/uploadPlantScoreDisplay/{ids}")
    public String uploadPlantScoreDisplay(@PathVariable String ids, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        String num = ids.split(",")[0];
        String reservationsId = ids.split(",")[1];
        String sql1 = "select * from root_plant_info a where a.num='" + num + "' and a.reservations_id='" + reservationsId + "' limit 1";
        RootImageInfo info = sqlMapper.selectOne(sql1, RootImageInfo.class);
        String sql = "select * from root_plant_info a left join root_plant_imgs_info b on a.num=b.num" +
                " where a.num='" + num + "' and a.reservations_id='" + reservationsId + "'";
        List<RootImageInfo> infoList = sqlMapper.selectList(sql, RootImageInfo.class);
        if (ShiroKit.getUser().getDoctorInfoList() == null) {
            String doctorListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + ShiroKit.getUser().getAbbreviation() + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            List<DoctorInfo> doctorInfoList=sqlMapper.selectList(doctorListSql,DoctorInfo.class);
            ShiroKit.getUser().setDoctorInfoList(doctorInfoList);
        }
        model.addAttribute("doctorList", ShiroKit.getUser().getDoctorInfoList());
        model.addAttribute("userName", ShiroKit.getUser().getAccount());
        model.addAttribute("infoList", infoList);
        model.addAttribute("num", num);
        model.addAttribute("info", info);
        model.addAttribute("reservationsId", reservationsId);
        return PREFIX + "doctor_uploadPlantScoreDisplay.html";
    }


    /**
     * 跳转到上传种植图片回显 - 质量检查
     */
    @RequestMapping(value = "/qualityPlantScoreDisplay/{ids}")
    public String qualityPlantScoreDisplay(@PathVariable String ids, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        String num = ids.split(",")[0];
        String reservationsId = ids.split(",")[1];
        String idsType = ids.split(",")[2];
        String sql1 = "select * from root_plant_info a where a.num='" + num + "' and a.reservations_id='" + reservationsId + "' limit 1";
        RootImageInfo info = sqlMapper.selectOne(sql1, RootImageInfo.class);
        String sql = "select * from root_plant_info a left join root_plant_imgs_info b on a.num=b.num" +
                " where a.num='" + num + "' and a.reservations_id='" + reservationsId + "' and  b.status=1";
        List<RootImageInfo> infoList = sqlMapper.selectList(sql, RootImageInfo.class);
        if (ShiroKit.getUser().getDoctorInfoList() == null) {
            String doctorListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + ShiroKit.getUser().getAbbreviation() + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            List<DoctorInfo> doctorInfoList=sqlMapper.selectList(doctorListSql,DoctorInfo.class);
            ShiroKit.getUser().setDoctorInfoList(doctorInfoList);
        }
        model.addAttribute("doctorList", ShiroKit.getUser().getDoctorInfoList());
        model.addAttribute("userName", ShiroKit.getUser().getAccount());
        model.addAttribute("infoList", infoList);
        model.addAttribute("num", num);
        model.addAttribute("info", info);
        model.addAttribute("reservationsId", reservationsId);
        if ("1".equals(idsType)) {
            // 种植术前
            return PREFIX + "quality_uploadPlantScoreDisplay1.html";
        } else {
            // 种植术后
            return PREFIX + "quality_uploadPlantScoreDisplay.html";
        }
    }

    /**
     * 跳转到上传种植戴牙
     */
    @RequestMapping(value = "/uploadPlantScoreComplex/{ids}")
    public String uploadPlantScoreComplex(@PathVariable String ids, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        String num = ids.split(",")[0];
        String reservationsId = ids.split(",")[1];
        String deletsql = "delete from root_plant_imgs_info where reservations_id='" + reservationsId + "' and status=0 and create_name='" + ShiroKit.getUser().getAccount() + "';";
        sqlMapper.delete(deletsql);
        if (ShiroKit.getUser().getDoctorInfoList() == null) {
            String doctorListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + ShiroKit.getUser().getAbbreviation() + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            List<DoctorInfo> doctorInfoList=sqlMapper.selectList(doctorListSql,DoctorInfo.class);
            ShiroKit.getUser().setDoctorInfoList(doctorInfoList);
        }
        model.addAttribute("doctorList", ShiroKit.getUser().getDoctorInfoList());
        model.addAttribute("userName", ShiroKit.getUser().getAccount());
        model.addAttribute("num", num);
        model.addAttribute("reservationsId", reservationsId);
        return PREFIX + "doctor_uploadPlantScoreComplex.html";
    }

    /**
     * 跳转到上传修复备牙前,后
     */
    @RequestMapping(value = "/uploadRepairScoreFirst/{rc}")
    public String uploadRepairScoreFirst(@PathVariable String rc, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        if (ShiroKit.getUser().getDoctorInfoList() == null) {
            String doctorListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + ShiroKit.getUser().getAbbreviation() + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            List<DoctorInfo> doctorInfoList=sqlMapper.selectList(doctorListSql,DoctorInfo.class);
            ShiroKit.getUser().setDoctorInfoList(doctorInfoList);
        }
        model.addAttribute("doctorList", ShiroKit.getUser().getDoctorInfoList());
        String reservationsId = rc.split(",")[0];
        String customerName = rc.split(",")[1];
        String randomNumber = "select DATE_FORMAT(now(),'%Y%m%d%k%i%S') as randomNumber from dual";
        DaulInfo infos = sqlMapper.selectOne(randomNumber, DaulInfo.class);
        String deletsql = "delete from root_repair_imgs_info where reservations_id='" + reservationsId + "' and status=0 and create_name='" + ShiroKit.getUser().getAccount() + "';";
        sqlMapper.delete(deletsql);
        model.addAttribute("num", infos.getRandomNumber());
        model.addAttribute("userName", ShiroKit.getUser().getAccount());
        model.addAttribute("customerName", customerName);
        return PREFIX + "doctor_uploadRepairScoreFirst.html";
    }

    /**
     * 跳转到上传修复图片回显 - 质量检测
     */
    @RequestMapping(value = "/qualityRepairScoreDisplay/{ids}")
    public String qualityRepairScoreDisplay(@PathVariable String ids, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        String num = ids.split(",")[0];
        String reservationsId = ids.split(",")[1];
        String idsType = ids.split(",")[2];
        String sql1 = "select * from root_repair_info a where a.num='" + num + "' and a.reservations_id='" + reservationsId + "' limit 1";
        RootImageInfo info = sqlMapper.selectOne(sql1, RootImageInfo.class);
        String sql = "select * from root_repair_info a left join root_repair_imgs_info b on a.num=b.num" +
                " where a.num='" + num + "' and a.reservations_id='" + reservationsId + "' and b.status=1 ";
        List<RootImageInfo> infoList = sqlMapper.selectList(sql, RootImageInfo.class);
        if (ShiroKit.getUser().getDoctorInfoList() == null) {
            String doctorListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + ShiroKit.getUser().getAbbreviation() + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            List<DoctorInfo> doctorInfoList=sqlMapper.selectList(doctorListSql,DoctorInfo.class);
            ShiroKit.getUser().setDoctorInfoList(doctorInfoList);
        }
        model.addAttribute("doctorList", ShiroKit.getUser().getDoctorInfoList());
        model.addAttribute("userName", ShiroKit.getUser().getAccount());
        model.addAttribute("infoList", infoList);
        model.addAttribute("num", num);
        model.addAttribute("info", info);
        model.addAttribute("reservationsId", reservationsId);
        if ("1".equals(idsType)) {
            // 修复术前
            return PREFIX + "quality_uploadRepairScoreDisplay1.html";
        } else {
            // 修复术后
            return PREFIX + "quality_uploadRepairScoreDisplay.html";
        }
    }

    /**
     * 跳转到上传修复图片回显
     */
    @RequestMapping(value = "/uploadRepairScoreDisplay/{ids}")
    public String uploadRepairScoreDisplay(@PathVariable String ids, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        String num = ids.split(",")[0];
        String reservationsId = ids.split(",")[1];
        String sql1 = "select * from root_repair_info a where a.num='" + num + "' and a.reservations_id='" + reservationsId + "' limit 1";
        RootImageInfo info = sqlMapper.selectOne(sql1, RootImageInfo.class);
        String sql = "select * from root_repair_info a left join root_repair_imgs_info b on a.num=b.num" +
                " where a.num='" + num + "' and a.reservations_id='" + reservationsId + "'";
        List<RootImageInfo> infoList = sqlMapper.selectList(sql, RootImageInfo.class);
        if (ShiroKit.getUser().getDoctorInfoList() == null) {
            String doctorListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + ShiroKit.getUser().getAbbreviation() + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            List<DoctorInfo> doctorInfoList=sqlMapper.selectList(doctorListSql,DoctorInfo.class);
            ShiroKit.getUser().setDoctorInfoList(doctorInfoList);
        }
        model.addAttribute("doctorList", ShiroKit.getUser().getDoctorInfoList());
        model.addAttribute("userName", ShiroKit.getUser().getAccount());
        model.addAttribute("infoList", infoList);
        model.addAttribute("num", num);
        model.addAttribute("info", info);
        model.addAttribute("reservationsId", reservationsId);
        return PREFIX + "doctor_uploadRepairScoreDisplay.html";
    }

    /**
     * 跳转到上传修复戴牙
     */
    @RequestMapping(value = "/uploadRepairScoreComplex/{ids}")
    public String uploadRepairScoreComplex(@PathVariable String ids, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        String num = ids.split(",")[0];
        String reservationsId = ids.split(",")[1];
        String deletsql = "delete from root_repair_imgs_info where reservations_id='" + reservationsId + "' and status=0 and create_name='" + ShiroKit.getUser().getAccount() + "';";
        sqlMapper.delete(deletsql);
        if (ShiroKit.getUser().getDoctorInfoList() == null) {
            String doctorListSql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid like CONCAT('%',b.id,',','%') left join role c on find_in_set(c.id,a.roleid) > 0 " +
                    " where b.abbreviation='" + ShiroKit.getUser().getAbbreviation() + "' and (c.name='医生' or c.name='洁牙师') and a.status='1';";
            List<DoctorInfo> doctorInfoList = sqlMapper.selectList(doctorListSql, DoctorInfo.class);
            ShiroKit.getUser().setDoctorInfoList(doctorInfoList);
        }
        model.addAttribute("doctorList", ShiroKit.getUser().getDoctorInfoList());
        model.addAttribute("userName", ShiroKit.getUser().getAccount());
        model.addAttribute("num", num);
        model.addAttribute("reservationsId", reservationsId);
        return PREFIX + "doctor_uploadRepairScoreComplex.html";
    }

    /**
     * 上传根管(上传到项目的webapp/static/img)
     */
    //@Transactional
    @RequestMapping(method = RequestMethod.POST, path = "/upLoadOrthodontics1/{cri}")
    @ResponseBody
    public String upLoadOrthodontics1(@RequestPart("file") MultipartFile picture, @PathVariable String cri) {
        String num = cri.split(",")[0];
        String imgtpye = cri.split(",")[1];
        String classification = cri.split(",")[2];
        String reservationsId = cri.split(",")[3];
        String realPath = "D:\\8068\\apache-tomcat-8.0.30\\webapps\\ROOT\\yingxiang\\orthodontics";
        String httpUrl = "http://118.123.15.60:8068/yingxiang/orthodontics/";
        //避免出现相同的图片名称  ids
        String randomNumbersql = "select DATE_FORMAT(now(),'%Y%m%d%k%i%S') as randomNumber from dual";
        DaulInfo infos = sqlMapper.selectOne(randomNumbersql, DaulInfo.class);
        String imageurl = "yingxiang/orthodontics/" + infos.getRandomNumber() + ".png";
        try {
//            FileUtils.copyInputStreamToFile(picture.getInputStream(), new File(realPath, infos.getRandomNumber() + ".png"));
            aliyunOssUtil.pushSingleFile(picture, imageurl);
            String sql = "INSERT INTO `root_orthodontics_imgs_info` (`image_url`, `num`, `imgtpye`, `classification`,reservations_id,create_name,status) VALUES " +
                    "( '" + MemberEnumConfig.ossphoeurl + imageurl + "', '" + num + "', '" + imgtpye + "', '" + classification + "','" + reservationsId + "','" + ShiroKit.getUser().getAccount() + "','1');";
            sqlMapper.insert(sql);
            String upSql = "update root_orthodontics_info a set a.shu_status=1,a.create_time='" + DateTimeKit.now() + "' where a.num='" + num + "' and a.reservations_id='" + reservationsId + "'";
            sqlMapper.insert(upSql);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return MemberEnumConfig.ossphoeurl + imageurl;
    }

    /**
     * 上传根管(上传到项目的webapp/static/img)
     */
    //@Transactional
    @RequestMapping(method = RequestMethod.POST, path = "/upLoadOrthodontics/{cri}")
    @ResponseBody
    public String upLoadOrthodontics(@RequestPart("file") MultipartFile picture,
                                     @PathVariable String cri) {
        return service.upLoadOrthodontics(picture, cri);
    }

    /**
     * 上传根管(上传到项目的webapp/static/img)
     */
    //@Transactional
    @RequestMapping(method = RequestMethod.POST, path = "/upLoadRootCanal/{cri}")
    @ResponseBody
    public String upLoadRootCanal(@RequestPart("file") MultipartFile picture,
                                  @PathVariable String cri) {
        return service.upLoadRootCanal(picture, cri);
    }

    /**
     * 上传潔牙(上传到项目的webapp/static/img)
     */
    @RequestMapping(method = RequestMethod.POST, path = "/uploadScaling/{cri}")
    @ResponseBody
    public String uploadScaling(@RequestPart("file") MultipartFile picture,
                                @PathVariable String cri) {
        return service.uploadScaling(picture, cri);
    }

    /**
     * 上传牙周(上传到项目的webapp/static/img)
     */
    @RequestMapping(method = RequestMethod.POST, path = "/uploadPeriodontal/{cri}")
    @ResponseBody
    public String uploadPeriodontal(@RequestPart("file") MultipartFile picture,
                                    @PathVariable String cri) {
        return service.uploadPeriodontal(picture, cri);
    }

    /**
     * 上传种植(上传到项目的webapp/static/img)
     */
    @RequestMapping(method = RequestMethod.POST, path = "/uploadPlantScoreFirst/{cri}")
    @ResponseBody
    public String uploadPlantScoreFirst(@RequestPart("file") MultipartFile picture,
                                        @PathVariable String cri) {
        return service.uploadPlantScoreFirst(picture, cri);
    }

    /**
     * 上传牙周(上传到项目的webapp/static/img)
     */
    @RequestMapping(method = RequestMethod.POST, path = "/uploadRepair/{cri}")
    @ResponseBody
    public String uploadRepair(@RequestPart("file") MultipartFile picture,
                               @PathVariable String cri) {
        return service.uploadRepair(picture, cri);
    }

    /**
     * 缓存上传正畸
     */
    @RequestMapping(value = "/storageOrthodontics", method = RequestMethod.POST)
    @ResponseBody
    public int storageOrthodontics(String reservationsId, String num, String doctor, String nurse, String customerName, String sex, String orthodonticsAge, String orthodonticDesign,
                                   String congestionDegree, String coveringCoverage, String molarRelationship, String canineRelationship, String designScheme) throws Exception {
        String selsql = "select id from root_orthodontics_info where num='" + num + "' limit 1;";
        DaulInfo daulInfo = sqlMapper.selectOne(selsql, DaulInfo.class);
        if (daulInfo == null) {
            String insertSql = "INSERT INTO root_orthodontics_info (`reservations_id`,`num`,`create_name`,create_time,doctor,nurse,customer_name,customer_sex," +
                    "congestion_degree,covering_coverage,molar_relationship,canine_relationship,design_scheme,orthodontics_age,arrival_store,orthodontic_design) VALUES " +
                    "('" + reservationsId + "','" + num + "','" + ShiroKit.getUser().getAccount() + "','" + DateTimeKit.now() + "','" + doctor + "','" + nurse + "','" + customerName + "','" + sex + "'" +
                    ",'" + congestionDegree + "','" + coveringCoverage + "','" + molarRelationship + "','" + canineRelationship + "','" + designScheme + "','" + orthodonticsAge + "','" + ShiroKit.getUser().getOutpatientName() + "','" + orthodonticDesign + "');";
            sqlMapper.insert(insertSql);
        } else {
            String updateSql = "update root_orthodontics_info a set a.congestion_degree='" + congestionDegree + "',a.orthodontic_design='" + orthodonticDesign + "',a.doctor='" + doctor + "',a.nurse='" + nurse + "',a.covering_coverage='" + coveringCoverage + "',a.molar_relationship='" + molarRelationship + "',a.canine_relationship='" + canineRelationship + "'," +
                    "a.design_scheme='" + designScheme + "',a.orthodontics_age='" + orthodonticsAge + "',a.customer_sex='" + sex + "',a.create_time='" + DateTimeKit.now() + "' where num='" + num + "' and reservations_id='" + reservationsId + "' and create_name='" + ShiroKit.getUser().getAccount() + "'";
            sqlMapper.update(updateSql);
        }
        String upimgs = "update root_orthodontics_imgs_info set status=1 where num='" + num + "' and reservations_id='" + reservationsId + "' " +
                " and create_name='" + ShiroKit.getUser().getAccount() + "';";
        return sqlMapper.update(upimgs);
    }

    /**
     * 正畸 初诊 暂存打分
     */
    @RequestMapping(value = "/orthodonticScoring", method = RequestMethod.POST)
    @ResponseBody
    public int orthodonticScoring(String reservationsId, String num, String a1, String a2, String a3, String a4, String a5, String a6, String a7, String C1, String C2, String C3, String C4, String C5, String C6, String degreeRadio, String expertComment1, String expertComment2) throws Exception {
        if (StringUtil.isEmpty(a1)) {
            a1 = "";
        }
        if (StringUtil.isEmpty(a2)) {
            a2 = "";
        }
        if (StringUtil.isEmpty(a3)) {
            a3 = "";
        }
        if (StringUtil.isEmpty(a4)) {
            a4 = "";
        }
        if (StringUtil.isEmpty(a5)) {
            a5 = "";
        }
        if (StringUtil.isEmpty(a6)) {
            a6 = "";
        }
        if (StringUtil.isEmpty(a7)) {
            a7 = "";
        }
        if (StringUtil.isEmpty(expertComment1)) {
            expertComment1 = "";
        }
        if (StringUtil.isEmpty(expertComment2)) {
            expertComment2 = "";
        }
        String updateSql = "update root_orthodontics_info a set a.A1='" + a1 + "',a.A2='" + a2 + "',a.A3='" + a3 + "',a.A4='" + a4 + "',a.A5='" + a5 + "',a.A6='" + a6 + "'," +
                "a.A7='" + a7 + "',a.hee_status = 1,a.C1='" + C1 + "',a.C2='" + C2 + "',a.C3='" + C3 + "',a.C4='" + C4 + "',a.C5='" + C5 + "',a.C6='" + C6 + "',a.degree_radio='" + degreeRadio + "',a.raters='" + ShiroKit.getUser().getAccount() + "',a.expert_comment1='" + expertComment1 + "',a.expert_comment2='" + expertComment2 + "' where num='" + num + "' and reservations_id='" + reservationsId + "'";
        return sqlMapper.update(updateSql);
    }

    /**
     * 正畸 完成 暂存打分
     */
    @RequestMapping(value = "/orthodonticScoringed", method = RequestMethod.POST)
    @ResponseBody
    public int orthodonticScoringed(String reservationsId, String num, String b1, String b2, String b3, String b4, String b5) throws Exception {
        if (StringUtil.isEmpty(b1)) {
            b1 = "";
        }
        if (StringUtil.isEmpty(b2)) {
            b2 = "";
        }
        if (StringUtil.isEmpty(b3)) {
            b3 = "";
        }
        if (StringUtil.isEmpty(b4)) {
            b4 = "";
        }
        if (StringUtil.isEmpty(b5)) {
            b5 = "";
        }
        String updateSql = "update root_orthodontics_info a set a.B1='" + b1 + "',a.B2='" + b2 + "',a.B3='" + b3 + "',a.B4='" + b4 + "',a.B5='" + b5 + "' where num='" + num + "' and reservations_id='" + reservationsId + "'";
        return sqlMapper.update(updateSql);
    }

    /**
     * 提交上传正畸
     */
    @RequestMapping(value = "/subOrthodontics", method = RequestMethod.POST)
    @ResponseBody
    public int subOrthodontics(String reservationsId, String num, String doctor, String nurse, String customerName, String sex, String orthodonticsAge, String orthodonticDesign,
                               String congestionDegree, String coveringCoverage, String molarRelationship, String canineRelationship, String designScheme, String medicalRecordNumberValue) throws Exception {
        String selsql = "select id,doctor,nurse from root_orthodontics_info where num='" + num + "' limit 1;";
        DaulInfo daulInfo = sqlMapper.selectOne(selsql, DaulInfo.class);
        if (daulInfo == null) {
            String insertSql = "INSERT INTO root_orthodontics_info (`reservations_id`,`num`,`create_name`,create_time,`status`,arrival_store,doctor,nurse,customer_name,congestion_degree,covering_coverage,molar_relationship,canine_relationship,design_scheme,orthodontics_age,customer_sex,medical_record_number,orthodontic_design,submission_state) VALUES " +
                    "('" + reservationsId + "','" + num + "','" + ShiroKit.getUser().getAccount() + "','" + DateTimeKit.now() + "',1,'" + ShiroKit.getUser().getOutpatientName() + "','" + doctor + "','" + nurse + "','" + customerName + "'," +
                    "'" + congestionDegree + "','" + coveringCoverage + "','" + molarRelationship + "','" + canineRelationship + "','" + designScheme + "','" + orthodonticsAge + "','" + sex + "','" + medicalRecordNumberValue + "','" + orthodonticDesign + "','1');";
            String upimgs = "update root_orthodontics_imgs_info set status=1 where num='" + num + "' and reservations_id='" + reservationsId + "' " +
                    " and create_name='" + ShiroKit.getUser().getAccount() + "';";
            sqlMapper.update(upimgs);
            return sqlMapper.insert(insertSql);
        } else {
            String updateSql = "update root_orthodontics_info a set a.status=1,a.submission_state=1,a.congestion_degree='" + congestionDegree + "',a.orthodontic_design='" + orthodonticDesign + "',a.doctor='" + doctor + "',a.nurse='" + nurse + "',a.covering_coverage='" + coveringCoverage + "',a.molar_relationship='" + molarRelationship + "'," +
                    "a.canine_relationship='" + canineRelationship + "', a.design_scheme='" + designScheme + "',a.orthodontics_age='" + orthodonticsAge + "',a.customer_sex='" + sex + "',a.create_time='" + DateTimeKit.now() + "',a.medical_record_number='" + medicalRecordNumberValue + "' where num='" + num + "' and reservations_id='" + reservationsId + "' " +
                    " and create_name='" + ShiroKit.getUser().getAccount() + "';";
            String upimgs = "update root_orthodontics_imgs_info set status=1 where num='" + num + "' and reservations_id='" + reservationsId + "' " +
                    " and create_name='" + ShiroKit.getUser().getAccount() + "';";
            sqlMapper.update(upimgs);
            return sqlMapper.update(updateSql);
        }
    }

    /**
     * 提交2上传正畸
     */
    @RequestMapping(value = "/subOrthodontics2", method = RequestMethod.POST)
    @ResponseBody
    public int subOrthodontics2(String reservationsId, String num, String doctor, String nurse, String customerName, String sex, String orthodonticsAge, String orthodonticDesign,
                                String congestionDegree, String coveringCoverage, String molarRelationship, String canineRelationship, String designScheme, String medicalRecordNumberValue) throws Exception {
        String selsql = "select id,doctor,nurse from root_orthodontics_info where num='" + num + "' limit 1;";
        DaulInfo daulInfo = sqlMapper.selectOne(selsql, DaulInfo.class);
        if (daulInfo == null) {
            String insertSql = "INSERT INTO root_orthodontics_info (`reservations_id`,`num`,`create_name`,create_time,`status`,arrival_store,doctor,nurse,customer_name,congestion_degree,covering_coverage,molar_relationship,canine_relationship,design_scheme,orthodontics_age,customer_sex,medical_record_number,orthodontic_design) VALUES " +
                    "('" + reservationsId + "','" + num + "','" + ShiroKit.getUser().getAccount() + "','" + DateTimeKit.now() + "',0,'" + ShiroKit.getUser().getOutpatientName() + "','" + doctor + "','" + nurse + "','" + customerName + "'," +
                    "'" + congestionDegree + "','" + coveringCoverage + "','" + molarRelationship + "','" + canineRelationship + "','" + designScheme + "','" + orthodonticsAge + "','" + sex + "','" + medicalRecordNumberValue + "','" + orthodonticDesign + "');";
            String upimgs = "update root_orthodontics_imgs_info set status=1 where num='" + num + "' and reservations_id='" + reservationsId + "' " +
                    " and create_name='" + ShiroKit.getUser().getAccount() + "';";
            sqlMapper.update(upimgs);
            return sqlMapper.insert(insertSql);
        } else {
            String updateSql = "update root_orthodontics_info a set a.congestion_degree='" + congestionDegree + "',a.orthodontic_design='" + orthodonticDesign + "',a.doctor='" + doctor + "',a.nurse='" + nurse + "',a.covering_coverage='" + coveringCoverage + "',a.molar_relationship='" + molarRelationship + "'," +
                    "a.canine_relationship='" + canineRelationship + "', a.design_scheme='" + designScheme + "',a.orthodontics_age='" + orthodonticsAge + "',a.customer_sex='" + sex + "',a.create_time='" + DateTimeKit.now() + "',a.medical_record_number='" + medicalRecordNumberValue + "' where num='" + num + "' and reservations_id='" + reservationsId + "' " +
                    " and create_name='" + ShiroKit.getUser().getAccount() + "';";
            String upimgs = "update root_orthodontics_imgs_info set status=1 where num='" + num + "' and reservations_id='" + reservationsId + "' " +
                    " and create_name='" + ShiroKit.getUser().getAccount() + "';";
            sqlMapper.update(upimgs);
            return sqlMapper.update(updateSql);
        }
    }

    /**
     * 缓存上传正畸完成
     */
    @RequestMapping(value = "/storageOrthodonticsd", method = RequestMethod.POST)
    @ResponseBody
    public int storageOrthodonticsd(String reservationsId, String num, String doctor, String nurse, String molarTooth, String canineTooth, String overlap) throws Exception {
        String updateSql = "update root_orthodontics_info a set a.doctor1='" + doctor + "',a.status=2,a.molar_tooth='" + molarTooth + "',a.canine_tooth='" + canineTooth + "',a.overlap='" + overlap + "',a.nurse1='" + nurse + "' " +
                " where num='" + num + "' and reservations_id='" + reservationsId + "' and create_name='" + ShiroKit.getUser().getAccount() + "'";
        String upimgs = "update root_orthodontics_imgs_info set status=1 where num='" + num + "' and reservations_id='" + reservationsId + "' " +
                " and create_name='" + ShiroKit.getUser().getAccount() + "';";
        sqlMapper.update(upimgs);
        return sqlMapper.update(updateSql);
    }


    /**
     * 提交正畸打分
     */
    @RequestMapping(value = "/subCore", method = RequestMethod.POST)
    @ResponseBody
    public int subCore(String reservationsId, String num, String a1, String a2, String a3, String a4, String a5, String a6, String a7, String C1, String C2, String C3, String C4, String C5, String C6, String degreeRadio, String expertComment1, String expertComment2) throws Exception {
        String updateSql = "update root_orthodontics_info a set a.A1='" + a1 + "',a.A2='" + a2 + "',a.A3='" + a3 + "',a.A4='" + a4 + "',a.A5='" + a5 + "',a.A6='" + a6 + "'," +
                "a.A7='" + a7 + "',a.C1='" + C1 + "',a.C2='" + C2 + "',a.C3='" + C3 + "',a.C4='" + C4 + "',a.C5='" + C5 + "',a.C6='" + C6 + "',a.degree_radio = '" + degreeRadio + "',a.raters='" + ShiroKit.getUser().getAccount() + "',a.expert_comment1='" + expertComment1 + "',a.expert_comment2='" + expertComment2 + "',a.hee_status=2,a.fen_status=1 where num='" + num + "' and reservations_id='" + reservationsId + "'";
        return sqlMapper.update(updateSql);
    }

    /**
     * 提交正畸打分
     */
    @RequestMapping(value = "/subCoreB", method = RequestMethod.POST)
    @ResponseBody
    public int subCoreB(String reservationsId, String num, String b1, String b2, String b3, String b4, String b5) throws Exception {
        String updateSql = "update root_orthodontics_info a set a.B1='" + b1 + "',a.B2='" + b2 + "',a.B3='" + b3 + "',a.B4='" + b4 + "',a.B5='" + b5 + "' where num='" + num + "' and reservations_id='" + reservationsId + "'";
        return sqlMapper.update(updateSql);
    }

    /**
     * 提交上传正畸完成
     */
    @RequestMapping(value = "/subOrthodonticsd", method = RequestMethod.POST)
    @ResponseBody
    public int subOrthodonticsd(String reservationsId, String num, String doctor, String nurse, String molarTooth, String canineTooth, String overlap, String medicalRecordNumberValue) throws Exception {
        String updateSql = "update root_orthodontics_info a set a.doctor1='" + doctor + "',a.status=3,a.submission_state2 = 1 ,a.nurse1='" + nurse + "',a.create_time='" + DateTimeKit.now() + "',a.medical_record_number='" + medicalRecordNumberValue + "',a.molar_tooth='" + molarTooth + "',a.canine_tooth='" + canineTooth + "',a.overlap='" + overlap + "' " +
                " where num='" + num + "' and reservations_id='" + reservationsId + "' and create_name='" + ShiroKit.getUser().getAccount() + "'";
        String upimgs = "update root_orthodontics_imgs_info set status=1 where num='" + num + "' and reservations_id='" + reservationsId + "' " +
                " and create_name='" + ShiroKit.getUser().getAccount() + "';";
        sqlMapper.update(upimgs);
        return sqlMapper.update(updateSql);
    }

    /**
     * 删除正畸初诊 暂存
     */
    @RequestMapping(value = "/deleteOrthodonticScore", method = RequestMethod.POST)
    @ResponseBody
    public int deleteOrthodonticScore(String ids) throws Exception {
        String num = ids.split(",")[0];
        String reservationsId = ids.split(",")[1];
        String selsql = "delete from root_orthodontics_info where num='" + num + "' and reservations_id='" + reservationsId + "' and status=0;";
        String selsql1 = "delete from root_orthodontics_imgs_info where num='" + num + "' and reservations_id='" + reservationsId + "' and classification=1 ;";
        sqlMapper.delete(selsql1);
        return sqlMapper.delete(selsql);
    }

    /**
     * 删除正畸完成 暂存
     */
    @RequestMapping(value = "/deleteOrthodonticScore1", method = RequestMethod.POST)
    @ResponseBody
    public int deleteOrthodonticScore1(String ids) throws Exception {
        String num = ids.split(",")[0];
        String reservationsId = ids.split(",")[1];
        String selsql = "update root_orthodontics_info a set a.status=1 where num='" + num + "' and reservations_id='" + reservationsId + "' and status=2;";
        String selsql1 = "delete from root_orthodontics_imgs_info where num='" + num + "' and reservations_id='" + reservationsId + "' and classification=2 ;";
        sqlMapper.delete(selsql1);
        return sqlMapper.update(selsql);
    }

    /**
     * 缓存上传种植
     */
    @RequestMapping(value = "/storagePlant", method = RequestMethod.POST)
    @ResponseBody
    public int storagePlant(String reservationsId, String num, String customerName, String doctor, String nurse) throws Exception {
        String selsql = "select id from root_plant_info where num='" + num + "' limit 1;";
        DaulInfo daulInfo = sqlMapper.selectOne(selsql, DaulInfo.class);
        if (daulInfo == null) {
            String insertSql = "INSERT INTO root_plant_info (`reservations_id`,`num`,`create_name`,create_time,arrival_store,doctor,nurse,customer_name) VALUES " +
                    "('" + reservationsId + "','" + num + "','" + ShiroKit.getUser().getAccount() + "','" + DateTimeKit.now() + "','" + ShiroKit.getUser().getOutpatientName() + "','" + doctor + "','" + nurse + "','" + customerName + "');";
            sqlMapper.insert(insertSql);
        }
        String upimgs = "update root_plant_imgs_info set status=1 where num='" + num + "' and reservations_id='" + reservationsId + "' " +
                " and create_name='" + ShiroKit.getUser().getAccount() + "';";
        return sqlMapper.update(upimgs);
    }

    /**
     * 提交上传种植
     */
    @RequestMapping(value = "/subPlant", method = RequestMethod.POST)
    @ResponseBody
    public int subPlant(String reservationsId, String num, String doctor1, String nurse1, String customerName) throws Exception {
        String selsql = "select id from root_plant_info where num='" + num + "' limit 1;";
        DaulInfo daulInfo = sqlMapper.selectOne(selsql, DaulInfo.class);
        if (daulInfo == null) {
            String insertSql = "INSERT INTO root_plant_info (`reservations_id`,`num`,`create_name`,create_time,`status`,arrival_store,doctor,nurse,customer_name) VALUES " +
                    "('" + reservationsId + "','" + num + "','" + ShiroKit.getUser().getAccount() + "','" + DateTimeKit.now() + "',1,'" + ShiroKit.getUser().getOutpatientName() + "','" + doctor1 + "','" + nurse1 + "','" + customerName + "');";
            String upimgs = "update root_plant_imgs_info set status=1 where num='" + num + "' and reservations_id='" + reservationsId + "' " +
                    " and create_name='" + ShiroKit.getUser().getAccount() + "';";
            sqlMapper.update(upimgs);
            return sqlMapper.insert(insertSql);
        } else {
            String updateSql = "update root_plant_info set status=1,doctor1 = '"+doctor1+"',nurse1 = '"+nurse1+"',create_time='" + DateTimeKit.now() + "' where num='" + num + "' and reservations_id='" + reservationsId + "' " +
                    " and create_name='" + ShiroKit.getUser().getAccount() + "';";
            String upimgs = "update root_plant_imgs_info set status=1 where num='" + num + "' and reservations_id='" + reservationsId + "' " +
                    " and create_name='" + ShiroKit.getUser().getAccount() + "';";
            sqlMapper.update(upimgs);
            return sqlMapper.update(updateSql);
        }
    }

    /**
     * 删除 缓存种植
     */
    @RequestMapping(value = "/deleteSubPlant", method = RequestMethod.POST)
    @ResponseBody
    public int deleteSubPlant(String ids) throws Exception {
        String num = ids.split(",")[0];
        String reservationsId = ids.split(",")[1];
        String selsql = "delete from root_plant_info where num='" + num + "' and reservations_id='" + reservationsId + "' ;";
        String selsql1 = "delete from root_plant_imgs_info where num='" + num + "' and reservations_id='" + reservationsId + "' ;";
        sqlMapper.delete(selsql1);
        return sqlMapper.delete(selsql);
    }

    /**
     * 缓存上传根管
     */
    @RequestMapping(value = "/storageRootCanal", method = RequestMethod.POST)
    @ResponseBody
    public int storageRootCanal(String reservationsId, String num, String treatmentTypes, String consumptionAmount, String toothPositionA,
                                String toothPositionB, String toothPositionC, String toothPositionD, String toothPosition, String doctor, String nurse, String customerName) throws Exception {
        String selsql = "select id from root_canal_info where num='" + num + "' limit 1;";
        DaulInfo daulInfo = sqlMapper.selectOne(selsql, DaulInfo.class);
        if (daulInfo == null) {
            String insertSql = "INSERT INTO root_canal_info (`reservations_id`,`num`, `treatment_types`, `consumption_amount`, " +
                    "`toothPositionA`, `toothPositionB`, `toothPositionC`, `toothPositionD`,`toothPosition`, `create_name`,arrival_store,doctor,nurse,customer_name) VALUES " +
                    "('" + reservationsId + "','" + num + "','" + treatmentTypes + "','" + consumptionAmount + "','" + toothPositionA + "','" + toothPositionB + "'," +
                    "'" + toothPositionC + "','" + toothPositionD + "','" + toothPosition + "','" + ShiroKit.getUser().getAccount() + "','" + ShiroKit.getUser().getOutpatientName() + "','" + doctor + "','" + nurse + "','" + customerName + "');";
            sqlMapper.insert(insertSql);
        }
        String upimgs = "update root_canal_imgs_info set status=1 where num='" + num + "' and reservations_id='" + reservationsId + "' " +
                " and create_name='" + ShiroKit.getUser().getAccount() + "';";
        return sqlMapper.update(upimgs);
    }

    /**
     * 提交上传根管
     */
    @RequestMapping(value = "/subRootCanal", method = RequestMethod.POST)
    @ResponseBody
    public int subRootCanal(String reservationsId, String num, String treatmentTypes, String consumptionAmount, String toothPositionA, String doctor, String nurse, String customerName,
                            String toothPositionB, String toothPositionC, String toothPositionD, String toothPosition) throws Exception {
        String selsql = "select id from root_canal_info where num='" + num + "' limit 1;";
        DaulInfo daulInfo = sqlMapper.selectOne(selsql, DaulInfo.class);
        if (daulInfo == null) {
            String insertSql = "INSERT INTO root_canal_info (`reservations_id`,`num`, `treatment_types`, `consumption_amount`, " +
                    "`toothPositionA`, `toothPositionB`, `toothPositionC`, `toothPositionD`,`toothPosition`, `create_name`,`status`,arrival_store,doctor,nurse,customer_name) VALUES " +
                    "('" + reservationsId + "','" + num + "','" + treatmentTypes + "','" + consumptionAmount + "','" + toothPositionA + "','" + toothPositionB + "'," +
                    "'" + toothPositionC + "','" + toothPositionD + "','" + toothPosition + "'," +
                    "'" + ShiroKit.getUser().getAccount() + "',1,'" + ShiroKit.getUser().getOutpatientName() + "','" + doctor + "','" + nurse + "','" + customerName + "');";
            String upimgs = "update root_canal_imgs_info set status=1 where num='" + num + "' and reservations_id='" + reservationsId + "' " +
                    " and create_name='" + ShiroKit.getUser().getAccount() + "';";
            sqlMapper.update(upimgs);
            return sqlMapper.insert(insertSql);
        } else {
            String updateSql = "update root_canal_info set status=1 where num='" + num + "' and reservations_id='" + reservationsId + "' " +
                    " and create_name='" + ShiroKit.getUser().getAccount() + "';";
            String upimgs = "update root_canal_imgs_info set status=1 where num='" + num + "' and reservations_id='" + reservationsId + "' " +
                    " and create_name='" + ShiroKit.getUser().getAccount() + "';";
            sqlMapper.update(upimgs);
            return sqlMapper.update(updateSql);
        }
    }

    /**
     * 删除暂存根管
     */
    @RequestMapping(value = "/deleteRootCanal", method = RequestMethod.POST)
    @ResponseBody
    public int deleteRootCanal(String ids) throws Exception {
        String num = ids.split(",")[0];
        String reservationsId = ids.split(",")[1];
        String selsql = "delete from root_canal_info where num='" + num + "' and reservations_id='" + reservationsId + "' ;";
        String selsql1 = "delete from root_canal_imgs_info where num='" + num + "' and reservations_id='" + reservationsId + "' ;";
        sqlMapper.delete(selsql1);
        return sqlMapper.delete(selsql);
    }

    /**
     * 缓存上传牙周
     */
    @RequestMapping(value = "/storagePeriodontal", method = RequestMethod.POST)
    @ResponseBody
    public int storagePeriodontal(String reservationsId, String num, String customerName, String doctor, String nurse) throws Exception {
        String selsql = "select id from root_periodontal_info where num='" + num + "' limit 1;";
        DaulInfo daulInfo = sqlMapper.selectOne(selsql, DaulInfo.class);
        if (daulInfo == null) {
            String insertSql = "INSERT INTO root_periodontal_info (`reservations_id`,`num`,`create_name`,arrival_store,doctor,nurse,customer_name) VALUES " +
                    "('" + reservationsId + "','" + num + "','" + ShiroKit.getUser().getAccount() + "','" + ShiroKit.getUser().getOutpatientName() + "','" + doctor + "','" + nurse + "','" + customerName + "');";
            sqlMapper.insert(insertSql);
        }
        String upimgs = "update root_periodontal_imgs_info set status=1 where num='" + num + "' and reservations_id='" + reservationsId + "' " +
                " and create_name='" + ShiroKit.getUser().getAccount() + "';";
        String upSql = "update root_periodontal_info a set a.doctor='" + doctor + "',a.nurse='" + nurse + "' where a.num='" + num + "' and a.reservations_id='" + reservationsId + "' " +
                " and a.create_name='" + ShiroKit.getUser().getAccount() + "';";
        sqlMapper.update(upSql);
        return sqlMapper.update(upimgs);
    }

    /**
     * 提交上传牙周
     */
    @RequestMapping(value = "/subPeriodontal", method = RequestMethod.POST)
    @ResponseBody
    public int subPeriodontal(String reservationsId, String num, String doctor, String nurse, String customerName) throws Exception {
        String selsql = "select id from root_periodontal_info where num='" + num + "' limit 1;";
        DaulInfo daulInfo = sqlMapper.selectOne(selsql, DaulInfo.class);
        if (daulInfo == null) {
            String insertSql = "INSERT INTO root_periodontal_info (`reservations_id`,`num`,`create_name`,`status`,arrival_store,doctor,nurse,customer_name) VALUES " +
                    "('" + reservationsId + "','" + num + "','" + ShiroKit.getUser().getAccount() + "',1,'" + ShiroKit.getUser().getOutpatientName() + "','" + doctor + "','" + nurse + "','" + customerName + "');";
            String upimgs = "update root_periodontal_imgs_info set status=1 where num='" + num + "' and reservations_id='" + reservationsId + "' " +
                    " and create_name='" + ShiroKit.getUser().getAccount() + "';";
            sqlMapper.update(upimgs);
            return sqlMapper.insert(insertSql);
        } else {
            String updateSql = "update root_periodontal_info set status=1 where num='" + num + "' and reservations_id='" + reservationsId + "' " +
                    " and create_name='" + ShiroKit.getUser().getAccount() + "';";
            String upimgs = "update root_periodontal_imgs_info set status=1 where num='" + num + "' and reservations_id='" + reservationsId + "' " +
                    " and create_name='" + ShiroKit.getUser().getAccount() + "';";
            sqlMapper.update(upimgs);
            return sqlMapper.update(updateSql);
        }
    }

    /**
     * 删除 缓存牙周
     */
    @RequestMapping(value = "/deleteStoragePeriodontal", method = RequestMethod.POST)
    @ResponseBody
    public int deleteStoragePeriodontal(String ids) throws Exception {
        String num = ids.split(",")[0];
        String reservationsId = ids.split(",")[1];
        String selsql = "delete from root_periodontal_info where num='" + num + "' and reservations_id='" + reservationsId + "' ;";
        String selsql1 = "delete from root_periodontal_imgs_info where num='" + num + "' and reservations_id='" + reservationsId + "' ;";
        sqlMapper.delete(selsql1);
        return sqlMapper.delete(selsql);
    }

    /**
     * 缓存上传洁牙
     */
    @RequestMapping(value = "/storageScaling", method = RequestMethod.POST)
    @ResponseBody
    public int storageScaling(String reservationsId, String num, String customerName, String doctor, String nurse) throws Exception {
        String selsql = "select id from root_scaling_info where num='" + num + "' limit 1;";
        DaulInfo daulInfo = sqlMapper.selectOne(selsql, DaulInfo.class);
        if (daulInfo == null) {
            String insertSql = "INSERT INTO root_scaling_info (`reservations_id`,`num`,`create_name`,arrival_store,doctor,nurse,customer_name) VALUES " +
                    "('" + reservationsId + "','" + num + "','" + ShiroKit.getUser().getAccount() + "','" + ShiroKit.getUser().getOutpatientName() + "','" + doctor + "','" + nurse + "','" + customerName + "');";
            sqlMapper.insert(insertSql);
        }
        String upimgs = "update root_scaling_imgs_info set status=1 where num='" + num + "' and reservations_id='" + reservationsId + "' " +
                " and create_name='" + ShiroKit.getUser().getAccount() + "';";
        return sqlMapper.update(upimgs);
    }

    /**
     * 提交上传洁牙
     */
    @RequestMapping(value = "/subScaling", method = RequestMethod.POST)
    @ResponseBody
    public int subScaling(String reservationsId, String num, String doctor, String nurse, String customerName) throws Exception {
        String selsql = "select id from root_scaling_info where num='" + num + "' limit 1;";
        DaulInfo daulInfo = sqlMapper.selectOne(selsql, DaulInfo.class);
        if (daulInfo == null) {
            String insertSql = "INSERT INTO root_scaling_info (`reservations_id`,`num`,`create_name`,`status`,arrival_store,doctor,nurse,customer_name) VALUES " +
                    "('" + reservationsId + "','" + num + "','" + ShiroKit.getUser().getAccount() + "',1,'" + ShiroKit.getUser().getOutpatientName() + "','" + doctor + "','" + nurse + "','" + customerName + "');";
            String upimgs = "update root_scaling_imgs_info set status=1 where num='" + num + "' and reservations_id='" + reservationsId + "' " +
                    " and create_name='" + ShiroKit.getUser().getAccount() + "';";
            sqlMapper.update(upimgs);
            return sqlMapper.insert(insertSql);
        } else {
            String updateSql = "update root_scaling_info set status=1 where num='" + num + "' and reservations_id='" + reservationsId + "' " +
                    " and create_name='" + ShiroKit.getUser().getAccount() + "';";
            String upimgs = "update root_scaling_imgs_info set status=1 where num='" + num + "' and reservations_id='" + reservationsId + "' " +
                    " and create_name='" + ShiroKit.getUser().getAccount() + "';";
            sqlMapper.update(upimgs);
            return sqlMapper.update(updateSql);
        }
    }

    /**
     * 删除 缓存洁牙
     */
    @RequestMapping(value = "/deleteSubScaling", method = RequestMethod.POST)
    @ResponseBody
    public int deleteSubScaling(String ids) throws Exception {
        String num = ids.split(",")[0];
        String reservationsId = ids.split(",")[1];
        String selsql = "delete from root_scaling_info where num='" + num + "' and reservations_id='" + reservationsId + "' ;";
        String selsql1 = "delete from root_scaling_imgs_info where num='" + num + "' and reservations_id='" + reservationsId + "' ;";
        sqlMapper.delete(selsql1);
        return sqlMapper.delete(selsql);
    }

    /**
     * 缓存上传修复
     */
    @RequestMapping(value = "/storageRepair", method = RequestMethod.POST)
    @ResponseBody
    public int storageRepair(String reservationsId, String num, String customerName, String doctor, String nurse) throws Exception {
        String selsql = "select id from root_repair_info where num='" + num + "' limit 1;";
        DaulInfo daulInfo = sqlMapper.selectOne(selsql, DaulInfo.class);
        if (daulInfo == null) {
            String insertSql = "INSERT INTO root_repair_info (`reservations_id`,`num`,`create_name`,arrival_store,doctor,nurse,customer_name) VALUES " +
                    "('" + reservationsId + "','" + num + "','" + ShiroKit.getUser().getAccount() + "','" + ShiroKit.getUser().getOutpatientName() + "','" + doctor + "','" + nurse + "','" + customerName + "');";
            sqlMapper.insert(insertSql);
        }
        String upimgs = "update root_repair_imgs_info set status=1 where num='" + num + "' and reservations_id='" + reservationsId + "' " +
                " and create_name='" + ShiroKit.getUser().getAccount() + "';";
        return sqlMapper.update(upimgs);
    }

    /**
     * 提交上传修复
     */
    @RequestMapping(value = "/subRepair", method = RequestMethod.POST)
    @ResponseBody
    public int subRepair(String reservationsId, String num, String doctor, String nurse, String customerName) throws Exception {
        String selsql = "select id from root_repair_info where num='" + num + "' limit 1;";
        DaulInfo daulInfo = sqlMapper.selectOne(selsql, DaulInfo.class);
        if (daulInfo == null) {
            String insertSql = "INSERT INTO root_repair_info (`reservations_id`,`num`,`create_name`,`status`,arrival_store,doctor,nurse,customer_name) VALUES " +
                    "('" + reservationsId + "','" + num + "','" + ShiroKit.getUser().getAccount() + "',1,'" + ShiroKit.getUser().getOutpatientName() + "','" + doctor + "','" + nurse + "','" + customerName + "');";
            String upimgs = "update root_repair_imgs_info set status=1 where num='" + num + "' and reservations_id='" + reservationsId + "' " +
                    " and create_name='" + ShiroKit.getUser().getAccount() + "';";
            sqlMapper.update(upimgs);
            return sqlMapper.insert(insertSql);
        } else {
            String updateSql = "update root_repair_info set status=1 where num='" + num + "' and reservations_id='" + reservationsId + "' " +
                    " and create_name='" + ShiroKit.getUser().getAccount() + "';";
            String upimgs = "update root_repair_imgs_info set status=1 where num='" + num + "' and reservations_id='" + reservationsId + "' " +
                    " and create_name='" + ShiroKit.getUser().getAccount() + "';";
            sqlMapper.update(upimgs);
            return sqlMapper.update(updateSql);
        }
    }

    /**
     * 删除 缓存修复
     */
    @RequestMapping(value = "/deleteSubRepair", method = RequestMethod.POST)
    @ResponseBody
    public int deleteSubRepair(String ids) throws Exception {
        String num = ids.split(",")[0];
        String reservationsId = ids.split(",")[1];
        String selsql = "delete from root_repair_info where num='" + num + "' and reservations_id='" + reservationsId + "' ;";
        String selsql1 = "delete from root_repair_imgs_info where num='" + num + "' and reservations_id='" + reservationsId + "' ;";
        sqlMapper.delete(selsql1);
        return sqlMapper.delete(selsql);
    }

    /**
     * 刪除上传更管
     */
    @RequestMapping(value = "/deleteRootCanalImgs", method = RequestMethod.POST)
    @ResponseBody
    public int deleteRootCanalImgs(String id) throws Exception {
        String delsql = "delete from root_canal_imgs_info where imgid='" + id + "'";
        return sqlMapper.delete(delsql);
    }

    /**
     * 刪除上传洁牙
     */
    @RequestMapping(value = "/deleteScalingImgs", method = RequestMethod.POST)
    @ResponseBody
    public int deleteScalingImgs(String id) throws Exception {
        String delsql = "delete from root_scaling_imgs_info where imgid='" + id + "'";
        return sqlMapper.delete(delsql);
    }

    /**
     * 刪除上传牙周
     */
    @RequestMapping(value = "/deletePeriodontalImgs", method = RequestMethod.POST)
    @ResponseBody
    public int deletePeriodontalImgs(String id) throws Exception {
        String delsql = "delete from root_periodontal_imgs_info where imgid='" + id + "'";
        return sqlMapper.delete(delsql);
    }

    /**
     * 刪除上传正畸
     */
    @RequestMapping(value = "/deleteOrthodonticsImgs", method = RequestMethod.POST)
    @ResponseBody
    public int deleteOrthodontics(String id) throws Exception {
        String delsql = "delete from root_orthodontics_imgs_info where imgid='" + id + "'";
        return sqlMapper.delete(delsql);
    }

    /**
     * 刪除上传种植
     */
    @RequestMapping(value = "/deletePlantImgs", method = RequestMethod.POST)
    @ResponseBody
    public int deletePlantImgs(String id) throws Exception {
        String delsql = "delete from root_plant_imgs_info where imgid='" + id + "'";
        return sqlMapper.delete(delsql);
    }

    /**
     * 刪除上传修复
     */
    @RequestMapping(value = "/deleteRepairImgs", method = RequestMethod.POST)
    @ResponseBody
    public int deleteRepairImgs(String id) throws Exception {
        String delsql = "delete from root_repair_imgs_info where imgid='" + id + "'";
        return sqlMapper.delete(delsql);
    }

    //跳转新增看诊项目界面
    @RequestMapping(value = "/add_project")
    public String addProject(Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        return PREFIX + "diagnose_project.html";
    }

    //跳转新增加工单位界面
    @RequestMapping(value = "/add_unit")
    public String addUnit(Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        return PREFIX + "processing_unit.html";
    }

    //跳转新增看诊项目界面
    @RequestMapping(value = "/doctor_addProject")
    public String doctor_addProject(Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        if (ShiroKit.getUser().getDepartmentList() == null) {
            String getListSql = "select a.department as department from " + ShiroKit.getUser().getPay_service_grade_info() + " a where a.is_upper=1 group by a.department order by a.id;";
            List<DepartmentInfo> departmentList=sqlMapper.selectList(getListSql,DepartmentInfo.class);
            ShiroKit.getUser().setDepartmentList(departmentList);
        }
        model.addAttribute("departmentList",ShiroKit.getUser().getDepartmentList());
        return PREFIX + "doctor_addProject.html";
    }

    //跳转增加加工单位界面
    @RequestMapping(value = "/add_process")
    public String doctor_addUnit(Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        return PREFIX + "doctor_processUint.html";
    }

    //跳转取件人界面
    @RequestMapping(value = "/add_picker")
    public String addPicker(Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        return PREFIX + "doctor_picker.html";
    }

    //跳转增加取件人界面
    @RequestMapping(value = "/add_picker_info")
    public String add_picker_info(Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        return PREFIX + "doctor_add_picker.html";
    }

    /**
     * 新增加工单位
     */
    @RequestMapping(value = "/add_process_unit", method = RequestMethod.POST)
    @ResponseBody
    public int addProcessUnit(String processUnit) throws Exception {
        String insertSql = "insert into processing_unit (add_name,process_unit,create_time) values ('" + ShiroKit.getUser().getAccount() + "','" + processUnit + "','" + DateTimeKit.now() + "')";
        sqlMapper.insert(insertSql);
        return 1;
    }

    /**
     * 新增加取件人
     */
    @RequestMapping(value = "/add_picker_name", method = RequestMethod.POST)
    @ResponseBody
    public int addPickerName(String picker) throws Exception {
        String insertSql = "insert into picker (add_name,picker,create_time) values ('" + ShiroKit.getUser().getAccount() + "','" + picker + "','" + DateTimeKit.now() + "')";
        sqlMapper.insert(insertSql);
        return 1;
    }

    /**
     * 新增看诊项目
     */
    @RequestMapping(value = "/add_diagnose", method = RequestMethod.POST)
    @ResponseBody
    public int addDiagnose(String projectCategory, String projectName) throws Exception {
        String insertSql = "insert into diagnose_project_info (add_name,project_category,project_name,update_time) values ('" + ShiroKit.getUser().getAccount() + "','" + projectCategory + "','" + projectName + "','" + DateTimeKit.now() + "')";
        sqlMapper.insert(insertSql);
        String selectSql = "select id,add_name as addName,project_category as projectCategory,project_name as projectName ," +
                "create_time as createTime,update_time as updateTime from diagnose_project_info;";
        ShiroKit.setSessionAttr("projectNameList", sqlMapper.selectList(selectSql));
        return 1;
    }

    /**
     * 修改看诊项目
     */
    @RequestMapping(value = "/update_diagnose", method = RequestMethod.POST)
    @ResponseBody
    public int updateDiagnose(String id, String projectCategory, String projectName) throws Exception {
        String updateSql = "update diagnose_project_info a set a.add_name='" + ShiroKit.getUser().getAccount() + "',a.project_category='" + projectCategory + "',a.project_name='" + projectName + "',a.update_time='" + DateTimeKit.now() + "' where id='" + id + "'";
        sqlMapper.update(updateSql);
        return 1;
    }

    /**
     * 删除看诊项目
     */
    @RequestMapping(value = "/delete_diagnose", method = RequestMethod.POST)
    @ResponseBody
    public int deleteDiagnose(String id) throws Exception {
        String deleteSql = "delete from diagnose_project_info where id='" + id + "'";
        sqlMapper.delete(deleteSql);
        String selectSql = "select id,add_name as addName,project_category as projectCategory,project_name as projectName ," +
                "create_time as createTime,update_time as updateTime from diagnose_project_info;";
        ShiroKit.setSessionAttr("projectNameList", sqlMapper.selectList(selectSql));
        return 1;
    }

    /**
     * 删除取件人
     */
    @RequestMapping(value = "/delete_picker", method = RequestMethod.POST)
    @ResponseBody
    public int deletePicker(String id) throws Exception {
        String deleteSql = "delete from picker where id='" + id + "'";
        sqlMapper.delete(deleteSql);
        return 1;
    }

    /**
     * 删除取件人
     */
    @RequestMapping(value = "/delete_process", method = RequestMethod.POST)
    @ResponseBody
    public int deleteProcess(String id) throws Exception {
        String deleteSql = "delete from processing_unit where id='" + id + "'";
        sqlMapper.delete(deleteSql);
        return 1;
    }

    //前台预约拖拽修改
    @RequestMapping(value = "/draftingUpdate/{cri}")
    @ResponseBody
    public int draftingUpdate(@PathVariable String cri) {
        String startTime = cri.split(",")[0];
        String endTime = cri.split(",")[1];
        String doctorId = cri.split(",")[2];
        String customerId = cri.split(",")[3];
        String doctor = "select account from user where id='" + doctorId + "' limit 1";
        User user = sqlMapper.selectOne(doctor, User.class);
        String sql = " update " + ShiroKit.getUser().getCustomer_info() + " set start_time='" + startTime + "',end_time='"
                + endTime + "',doctor=(select account from user where id='" + doctorId + "') where id='" + customerId + "'";
        String sql2 = "select t.customer_name as customerName,t.customer_phone as customerPhone," +
                " t.start_time as startTime,t.end_time as endTime,t.doctor as doctor,t.reservations_id as reservationsId from " +
                " " + ShiroKit.getUser().getCustomer_info() + " t where id='" + customerId + "' limit 1";
        CustomerInfo customerInfo = sqlMapper.selectOne(sql2, CustomerInfo.class);
        //插入视图改动日志 修改时间or医生
        String sq11 = "INSERT INTO `customer_reservations_update_log` (createtime,single_person,logtype, `userid`, `customer_status`, `customer_name`,`customer_phone`," +
                " `succeed`,outpatient_name ,`message`,customer_id,reservations_id) VALUES " +
                " ('" + DateTimeKit.now() + "','" + ShiroKit.getUser().getAccount() + "','修改预约','" + ShiroKit.getUser().getId() + "','预约', '"
                + customerInfo.getCustomerName() + "', '" + customerInfo.getCustomerPhone() + "','成功','" + ShiroKit.getUser().getOutpatientName() +
                "','预约时间：" + customerInfo.getStartTime().substring(0, 16) + " - " + customerInfo.getEndTime().substring(11, 16)
                + " -> " + startTime.substring(0, 16) + " - " + endTime.substring(11, 16) + "" +
                " </br> 医生：" + customerInfo.getDoctor() + " -> " + user.getAccount() + "','" + customerId + "','" + customerInfo.getReservationsId() + "');";
        sqlMapper.update(sql);
        webSocket.sendMessageViews("修改预约", ShiroKit.getUser().getAbbreviation());
        return sqlMapper.insert(sq11);
    }

    /**
     * 导入
     */
    @RequestMapping(value = "/returnImport")
    public String returnImport(@Valid MultipartFile file) {
        if (!StringUtil.isEmpty(file)) {
            Random random = new Random();
            String realPath = "D:\\yiyatmp\\" + random.nextInt(100);
            String FileInput = realPath + "\\" + file.getOriginalFilename();
            try {
                FileUtils.copyInputStreamToFile(file.getInputStream(), new File(realPath, file.getOriginalFilename()));
                InputStream is = new FileInputStream(FileInput);
                HSSFWorkbook hssfWorkbook = new HSSFWorkbook(is);
                // 循环工作表Sheet
                Sheet hssfSheet = hssfWorkbook.getSheetAt(0);
                Row hssfRow0 = hssfSheet.getRow(0);
                for (int rowNum = 1; rowNum <= hssfSheet.getLastRowNum(); rowNum++) {
                    Row hssfRow = hssfSheet.getRow(rowNum);
                    if (hssfRow == null) {
                        continue;
                    }
                    Cell xh1 = hssfRow.getCell(0);
                    Cell xh2 = hssfRow.getCell(1);
                    Cell xh3 = hssfRow.getCell(2);
                    Cell xh4 = hssfRow.getCell(3);
                    Cell xh5 = hssfRow.getCell(4);
                    Cell xh6 = hssfRow.getCell(5);
                    Cell xh7 = hssfRow.getCell(6);
                    Cell xh8 = hssfRow.getCell(7);
                    Cell xh9 = hssfRow.getCell(8);
                    Cell xh10 = hssfRow.getCell(9);
                    Cell xh11 = hssfRow.getCell(10);
                    Cell xh12 = hssfRow.getCell(11);
                    Cell xh13 = hssfRow.getCell(12);
                    Cell xh14 = hssfRow.getCell(13);
                    Cell xh15 = hssfRow.getCell(14);
                    Cell xh16 = hssfRow.getCell(15);
                    Cell xh17 = hssfRow.getCell(16);
                    Cell xh18 = hssfRow.getCell(17);
                    Cell xh19 = hssfRow.getCell(18);
                    Cell xh20 = hssfRow.getCell(19);
                    Cell xh21 = hssfRow.getCell(20);
                    Cell xh22 = hssfRow.getCell(21);
                    Cell xh23 = hssfRow.getCell(22);
                    String xh1s = "";
                    String xh2s = "";
                    String xh3s = "";
                    String xh4s = "";
                    String xh5s = "";
                    String xh6s = "";
                    String xh7s = "";
                    String xh8s = "";
                    String xh9s = "";
                    String xh10s = "";
                    String xh11s = "";
                    String xh12s = "";
                    String xh13s = "";
                    String xh14s = "";
                    String xh15s = "";
                    String xh16s = "";
                    String xh17s = "";
                    String xh18s = "";
                    String xh19s = "";
                    String xh20s = "";
                    String xh21s = "";
                    String xh22s = "";
                    if ((xh1 + "") == null || ("").equals((xh1 + ""))) {
                        xh1s = "null";
                    } else {
                        xh1s = "'" + xh1 + "'";
                    }
                    if ((xh2 + "") == null || ("").equals((xh2 + ""))) {
                        xh2s = "null";
                    } else {
                        xh2s = "'" + xh2 + "'";
                    }
                    if ((xh3 + "") == null || ("").equals((xh3 + ""))) {
                        xh3s = "null";
                    } else {
                        xh3s = "'" + xh3 + "'";
                    }
                    if ((xh4) == null || ("").equals((xh4 + ""))) {
                        xh4s = "null";
                    } else {
                        xh4s = "'" + xh4 + "'";
                    }
                    if ((xh5 + "") == null || ("").equals((xh5 + ""))) {
                        xh5s = "null";
                    } else {
                        xh5s = "'" + xh5 + "'";
                    }
                    if ((xh6 + "") == null || ("").equals((xh6 + ""))) {
                        xh6s = "null";
                    } else {
                        xh6s = "'" + xh6 + "'";
                    }
                    if ((xh7 + "") == null || ("").equals((xh7 + ""))) {
                        xh7s = "null";
                    } else {
                        xh7s = "'" + xh7 + "'";
                    }
                    if ((xh8 + "") == null || ("").equals((xh8 + ""))) {
                        xh8s = "null";
                    } else {
                        xh8s = "'" + xh8 + "'";
                    }
                    if ((xh9 + "") == null || ("").equals((xh9 + ""))) {
                        xh9s = "null";
                    } else {
                        xh9s = "'" + xh9 + "'";
                    }
                    if ((xh10 + "") == null || ("").equals((xh10 + ""))) {
                        xh10s = "null";
                    } else {
                        xh10s = "'" + xh10 + "'";
                    }
                    if ((xh11 + "") == null || ("").equals((xh11 + ""))) {
                        xh11s = "null";
                    } else {
                        xh11s = "'" + xh11 + "'";
                    }
                    if ((xh12 + "") == null || ("").equals((xh12 + ""))) {
                        xh12s = "null";
                    } else {
                        xh12s = "'" + xh12 + "'";
                    }
                    if ((xh13 + "") == null || ("").equals((xh13 + ""))) {
                        xh13s = "null";
                    } else {
                        xh13s = "'" + xh13 + "'";
                    }
                    if ((xh14 + "") == null || ("").equals((xh14 + ""))) {
                        xh14s = "null";
                    } else {
                        xh14s = "'" + xh14 + "'";
                    }
                    if ((xh15 + "") == null || ("").equals((xh15 + ""))) {
                        xh15s = "null";
                    } else {
                        xh15s = "'" + xh15 + "'";
                    }
                    if ((xh16 + "") == null || ("").equals((xh16 + ""))) {
                        xh16s = "null";
                    } else {
                        xh16s = "'" + xh16 + "'";
                    }
                    if ((xh17 + "") == null || ("").equals((xh17 + ""))) {
                        xh17s = "null";
                    } else {
                        xh17s = "'" + xh17 + "'";
                    }
                    if ((xh18 + "") == null || ("").equals((xh18 + ""))) {
                        xh18s = "null";
                    } else {
                        xh18s = "'" + xh18 + "'";
                    }
                    if ((xh19.toString()) == null || ("").equals((xh19.toString()))) {
                        xh19s = "null";
                    } else {
                        xh19s = "'" + xh19 + "'";
                    }
                    if ((xh20 + "") == null || ("").equals((xh20 + ""))) {
                        xh20s = "null";
                    } else {
                        xh20s = "'" + xh20 + "'";
                    }
                    if ((xh21 + "") == null || ("").equals((xh21 + ""))) {
                        xh21s = "null";
                    } else {
                        xh21s = "'" + xh21 + "'";
                    }
                    String insql = "INSERT INTO `re_v1` (`2`, `3`, `4`, `5`, `6`, `7`, `8`, `9`, `10`, `11`, `12`, `13`, `14`, `15`, `16`, `17`, `18`, `19`, `20`, `21`, `22`) VALUES " +
                            " (" + xh1s + "," + xh2s + "," + xh3s + "," + xh4s + "," + xh5s + "," + xh6s + "," + xh7s + "," + xh8s + "," + xh9s + "," + xh10s + "," + xh11s + "," + xh12s + "," +
                            "" + xh13s + "," + xh14s + "," + xh15s + "," + xh16s + "," + xh17s + "," + xh18s + "," + xh19s + "," + xh20s + "," + xh21s + ");";
                    sqlMapper.insert(insql);
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
            return "/testClose.html";
        } else {
            return "/testClose.html";
        }
    }

    @RequestMapping(value = "/upload1")
    public String returnImport1(@Valid MultipartFile file) {
        if (!StringUtil.isEmpty(file)) {
            Random random = new Random();
            String realPath = "D:\\yiyatmp\\" + random.nextInt(100);
            String FileInput = realPath + "\\" + file.getOriginalFilename();
            try {
                FileUtils.copyInputStreamToFile(file.getInputStream(), new File(realPath, file.getOriginalFilename()));
                InputStream is = new FileInputStream(FileInput);
                HSSFWorkbook hssfWorkbook = new HSSFWorkbook(is);
                // 循环工作表Sheet
                Sheet hssfSheet = hssfWorkbook.getSheetAt(0);
                Row hssfRow0 = hssfSheet.getRow(0);
                for (int rowNum = 1; rowNum <= hssfSheet.getLastRowNum(); rowNum++) {
                    Row hssfRow = hssfSheet.getRow(rowNum);
                    if (hssfRow == null) {
                        continue;
                    }
                    Cell xh1 = hssfRow.getCell(0);
                    Cell xh2 = hssfRow.getCell(1);
                    Cell xh3 = hssfRow.getCell(2);
                    Cell xh4 = hssfRow.getCell(3);
                    Cell xh5 = hssfRow.getCell(4);
                    Cell xh6 = hssfRow.getCell(5);
                    Cell xh7 = hssfRow.getCell(6);
                    Cell xh8 = hssfRow.getCell(7);
                    Cell xh9 = hssfRow.getCell(8);
                    Cell xh10 = hssfRow.getCell(9);
                    Cell xh11 = hssfRow.getCell(10);
                    Cell xh12 = hssfRow.getCell(11);
                    Cell xh13 = hssfRow.getCell(12);
                    Cell xh14 = hssfRow.getCell(13);
                    Cell xh15 = hssfRow.getCell(14);
                    Cell xh16 = hssfRow.getCell(15);
                    Cell xh17 = hssfRow.getCell(16);
                    Cell xh18 = hssfRow.getCell(17);
                    Cell xh19 = hssfRow.getCell(18);
                    Cell xh20 = hssfRow.getCell(19);
                    Cell xh21 = hssfRow.getCell(20);
                    Cell xh22 = hssfRow.getCell(21);
                    Cell xh23 = hssfRow.getCell(22);
                    Cell xh24 = hssfRow.getCell(23);
                    Cell xh25 = hssfRow.getCell(24);
                    Cell xh26 = hssfRow.getCell(25);
                    Cell xh27 = hssfRow.getCell(26);
                    String xh1s = "";
                    String xh2s = "";
                    String xh3s = "";
                    String xh4s = "";
                    String xh5s = "";
                    String xh6s = "";
                    String xh7s = "";
                    String xh8s = "";
                    String xh9s = "";
                    String xh10s = "";
                    String xh11s = "";
                    String xh12s = "";
                    String xh13s = "";
                    String xh14s = "";
                    String xh15s = "";
                    String xh16s = "";
                    String xh17s = "";
                    String xh18s = "";
                    String xh19s = "";
                    String xh20s = "";
                    String xh21s = "";
                    String xh22s = "";
                    String xh23s = "";
                    String xh24s = "";
                    String xh25s = "";
                    String xh26s = "";
                    String xh27s = "";
                    if ((xh1 + "") == null || ("").equals((xh1 + ""))) {
                        xh1s = "null";
                    } else {
                        xh1s = "'" + xh1 + "'";
                    }
                    if ((xh2 + "") == null || ("").equals((xh2 + ""))) {
                        xh2s = "null";
                    } else {
                        xh2s = "'" + xh2 + "'";
                    }
                    if ((xh3 + "") == null || ("").equals((xh3 + ""))) {
                        xh3s = "null";
                    } else {
                        xh3s = "'" + xh3 + "'";
                    }
                    if ((xh4) == null || ("").equals((xh4 + ""))) {
                        xh4s = "null";
                    } else {
                        xh4s = "'" + xh4 + "'";
                    }
                    if ((xh5 + "") == null || ("").equals((xh5 + ""))) {
                        xh5s = "null";
                    } else {
                        xh5s = "'" + xh5 + "'";
                    }
                    if ((xh6 + "") == null || ("").equals((xh6 + ""))) {
                        xh6s = "null";
                    } else {
                        xh6s = "'" + xh6 + "'";
                    }
                    if ((xh7 + "") == null || ("").equals((xh7 + ""))) {
                        xh7s = "null";
                    } else {
                        xh7s = "'" + xh7 + "'";
                    }
                    if ((xh8 + "") == null || ("").equals((xh8 + ""))) {
                        xh8s = "null";
                    } else {
                        xh8s = "'" + xh8 + "'";
                    }
                    if ((xh9 + "") == null || ("").equals((xh9 + ""))) {
                        xh9s = "null";
                    } else {
                        xh9s = "'" + xh9 + "'";
                    }
                    if ((xh10 + "") == null || ("").equals((xh10 + ""))) {
                        xh10s = "null";
                    } else {
                        xh10s = "'" + xh10 + "'";
                    }
                    if ((xh11 + "") == null || ("").equals((xh11 + ""))) {
                        xh11s = "null";
                    } else {
                        xh11s = "'" + xh11 + "'";
                    }
                    if ((xh12 + "") == null || ("").equals((xh12 + ""))) {
                        xh12s = "null";
                    } else {
                        xh12s = "'" + xh12 + "'";
                    }
                    if ((xh13 + "") == null || ("").equals((xh13 + ""))) {
                        xh13s = "null";
                    } else {
                        xh13s = "'" + xh13 + "'";
                    }
                    if ((xh14 + "") == null || ("").equals((xh14 + ""))) {
                        xh14s = "null";
                    } else {
                        xh14s = "'" + xh14 + "'";
                    }
                    if ((xh15 + "") == null || ("").equals((xh15 + ""))) {
                        xh15s = "null";
                    } else {
                        xh15s = "'" + xh15 + "'";
                    }
                    if ((xh16 + "") == null || ("").equals((xh16 + ""))) {
                        xh16s = "null";
                    } else {
                        xh16s = "'" + xh16 + "'";
                    }
                    if ((xh17 + "") == null || ("").equals((xh17 + ""))) {
                        xh17s = "null";
                    } else {
                        xh17s = "'" + xh17 + "'";
                    }
                    if ((xh18 + "") == null || ("").equals((xh18 + ""))) {
                        xh18s = "null";
                    } else {
                        xh18s = "'" + xh18 + "'";
                    }
                    if ((xh19 + "") == null || ("").equals((xh19 + ""))) {
                        xh19s = "null";
                    } else {
                        xh19s = "'" + xh19 + "'";
                    }
                    if ((xh20 + "") == null || ("").equals((xh20 + ""))) {
                        xh20s = "null";
                    } else {
                        xh20s = "'" + xh20 + "'";
                    }
                    if ((xh21 + "") == null || ("").equals((xh21 + ""))) {
                        xh21s = "null";
                    } else {
                        xh21s = "'" + xh21 + "'";
                    }
                    if ((xh22 + "") == null || ("").equals((xh22 + ""))) {
                        xh22s = "null";
                    } else {
                        xh22s = "'" + xh22 + "'";
                    }
                    if ((xh23 + "") == null || ("").equals((xh23 + ""))) {
                        xh23s = "null";
                    } else {
                        xh23s = "'" + xh23 + "'";
                    }
                    if ((xh24 + "") == null || ("").equals((xh24 + ""))) {
                        xh24s = "null";
                    } else {
                        xh24s = "'" + xh24 + "'";
                    }
                    if ((xh25 + "") == null || ("").equals((xh25 + ""))) {
                        xh25s = "null";
                    } else {
                        xh25s = "'" + xh25 + "'";
                    }
                    if ((xh26 + "") == null || ("").equals((xh26 + ""))) {
                        xh26s = "null";
                    } else {
                        xh26s = "'" + xh26 + "'";
                    }
                    if ((xh27 + "") == null || ("").equals((xh27 + ""))) {
                        xh27s = "null";
                    } else {
                        xh27s = "'" + xh27 + "'";
                    }

                    String selstr = "select * from re_v1_copy where name=" + xh2s + " and phone=" + xh3s + " ";
                    Recopy recopy = sqlMapper.selectOne(selstr, Recopy.class);
                    if (recopy == null) {
                        String insql = "INSERT INTO `re_v1_copy` (`id`, `name` ,`phone` ,`money` ,`doctor` ,`dept` ,`sex`,`old`,`statuss`,`pay_s`,`arching`,`update_time`,`ap_time`," +
                                "`filling_time`,`first_time`,`one_m`,`two_m`,`thr_m`,`one_c`,`two_c`,`thr_c`,`remarks`,`content`,`jiedai_content`,`follwer`,`huifang`,`project`) VALUES " +
                                " (" + xh1s + "," + xh2s + "," + xh3s + "," + xh4s + "," + xh5s + "," + xh6s + "," + xh7s + "," + xh8s + "," + xh9s + "," + xh10s + "," + xh11s + "," + xh12s + "," +
                                "" + xh13s + "," + xh14s + "," + xh15s + "," + xh16s + "," + xh17s + "," + xh18s + "," + xh19s + "," + xh20s + "," + xh21s + "," + xh22s + "," + xh23s + "," + xh24s + "," + xh25s + "," + xh26s + "," + xh27s + ");";

                        sqlMapper.insert(insql);
                    }
//                    else{
//                        String upstr = "upate re_v1_copy a set a.money="+xh4s+",a.doctor="+xh5s+",a.dept="+xh6s+",a.statuss="+xh9s+",a.pay_s="+xh10s+",a.arching="+xh11s+",a.update_time="+xh12s+","
//                    }

                }
            } catch (IOException e) {
                e.printStackTrace();
            }
            return "/testClose.html";
        } else {
            return "/testClose.html";
        }
    }

    /**
     * 导入
     */
    @RequestMapping(value = "/upload")
    public String importTestQuestions(@Valid MultipartFile file) {
        if (!StringUtil.isEmpty(file)) {
            Random random = new Random();
            String realPath = "D:\\yiyatmp\\" + random.nextInt(100);
            String FileInput = realPath + "\\" + file.getOriginalFilename();
            try {
                FileUtils.copyInputStreamToFile(file.getInputStream(), new File(realPath, file.getOriginalFilename()));
                InputStream is = new FileInputStream(FileInput);
                HSSFWorkbook hssfWorkbook = new HSSFWorkbook(is);
                // 循环工作表Sheet
                Sheet hssfSheet = hssfWorkbook.getSheetAt(0);
                Row hssfRow0 = hssfSheet.getRow(0);
                for (int rowNum = 1; rowNum <= hssfSheet.getLastRowNum(); rowNum++) {
                    Row hssfRow = hssfSheet.getRow(rowNum);
                    if (hssfRow == null) {
                        continue;
                    }
                    Cell xh1 = hssfRow.getCell(0);
                    Cell xh2 = hssfRow.getCell(1);
                    Cell xh3 = hssfRow.getCell(2);
                    Cell xh4 = hssfRow.getCell(3);
                    Cell xh5 = hssfRow.getCell(4);
                    Cell xh6 = hssfRow.getCell(5);
                    Cell xh7 = hssfRow.getCell(6);
                    Cell xh8 = hssfRow.getCell(7);
                    Cell xh9 = hssfRow.getCell(8);
                    Cell xh10 = hssfRow.getCell(9);
                    Cell xh11 = hssfRow.getCell(10);
                    Cell xh12 = hssfRow.getCell(11);
                    Cell xh13 = hssfRow.getCell(12);
                    Cell xh14 = hssfRow.getCell(13);
                    Cell xh15 = hssfRow.getCell(14);
                    Cell xh16 = hssfRow.getCell(15);
                    String xh1s = "";
                    String xh2s = "";
                    String xh3s = "";
                    String xh4s = "";
                    String xh5s = "";
                    String xh6s = "";
                    String xh7s = "";
                    String xh8s = "";
                    String xh9s = "";
                    String xh10s = "";
                    String xh11s = "";
                    String xh12s = "";
                    String xh13s = "";
                    String xh14s = "";
                    String xh15s = "";
                    String xh16s = "";
                    if ((xh1 + "") == null || ("").equals((xh1 + ""))) {
                        xh1s = "null";
                    } else {
                        xh1s = "'" + xh1 + "'";
                    }
                    if ((xh2 + "") == null || ("").equals((xh2 + ""))) {
                        xh2s = "null";
                    } else {
                        xh2s = "'" + xh2 + "'";
                    }
                    if ((xh3 + "") == null || ("").equals((xh3 + ""))) {
                        xh3s = "null";
                    } else {
                        xh3s = "'" + xh3 + "'";
                    }
                    if ((xh4) == null || ("").equals((xh4 + ""))) {
                        xh4s = "null";
                    } else {
                        xh4s = "'" + xh4 + "'";
                    }
                    if ((xh5 + "") == null || ("").equals((xh5 + ""))) {
                        xh5s = "null";
                    } else {
                        xh5s = "'" + xh5 + "'";
                    }
                    if ((xh6 + "") == null || ("").equals((xh6 + ""))) {
                        xh6s = "null";
                    } else {
                        xh6s = "'" + xh6 + "'";
                    }
                    if ((xh7 + "") == null || ("").equals((xh7 + ""))) {
                        xh7s = "null";
                    } else {
                        xh7s = "'" + xh7 + "'";
                    }
                    if ((xh8 + "") == null || ("").equals((xh8 + ""))) {
                        xh8s = "null";
                    } else {
                        xh8s = "'" + xh8 + "'";
                    }
                    if ((xh9 + "") == null || ("").equals((xh9 + ""))) {
                        xh9s = "null";
                    } else {
                        xh9s = "'" + xh9 + "'";
                    }
                    if ((xh10 + "") == null || ("").equals((xh10 + ""))) {
                        xh10s = "null";
                    } else {
                        xh10s = "'" + xh10 + "'";
                    }
                    if ((xh11 + "") == null || ("").equals((xh11 + ""))) {
                        xh11s = "null";
                    } else {
                        xh11s = "'" + xh11 + "'";
                    }
                    if ((xh12 + "") == null || ("").equals((xh12 + ""))) {
                        xh12s = "null";
                    } else {
                        xh12s = "'" + xh12 + "'";
                    }
                    if ((xh13 + "") == null || ("").equals((xh13 + ""))) {
                        xh13s = "null";
                    } else {
                        xh13s = "'" + xh13 + "'";
                    }
                    if ((xh14 + "") == null || ("").equals((xh14 + ""))) {
                        xh14s = "null";
                    } else {
                        xh14s = "'" + xh14 + "'";
                    }
                    if ((xh15 + "") == null || ("").equals((xh15 + ""))) {
                        xh15s = "null";
                    } else {
                        xh15s = "'" + xh15 + "'";
                    }
                    if ((xh16 + "") == null || ("").equals((xh16 + ""))) {
                        xh16s = "null";
                    } else {
                        xh16s = "'" + xh16 + "'";
                    }
                    String id = CommUtils.getUUID();
                    Random rand = new Random();
                    int randomNumber1 = rand.nextInt(9999999);
                    int randomNumber2 = rand.nextInt(999999);
                    id = randomNumber1 + id + randomNumber2;
//                    String reservationsInfoId = "";
//                    String selectsql1 = "select reservations_id as reservationsId from " + ShiroKit.getUser().getCustomer_info() + " a where arrival_status!=1 and arrival_status!=6 and arrival_status!=7 and arrival_status!=8 and arrival_status!=9 and arrival_status!=10 and a.medical_record_number=" + xh2s + " limit 0,1";
//                    ReservationsInfo reservationsInfo1 = sqlMapper.selectOne(selectsql1, ReservationsInfo.class);
//                    if (reservationsInfo1 != null) {
//                        reservationsInfoId = reservationsInfo1.getReservationsId();
//                    } else {
//                        String selectsql2 = "select reservations_id as reservationsId from " + ShiroKit.getUser().getCustomer_info() + " a where arrival_status!=1 and arrival_status!=6 and arrival_status!=7 and arrival_status!=8 and arrival_status!=9 and arrival_status!=10 and a.customer_name=" + xh1s + " limit 0,1";
//                        ReservationsInfo reservationsInfo2 = sqlMapper.selectOne(selectsql2, ReservationsInfo.class);
//                        if (reservationsInfo2 != null) {
//                            reservationsInfoId = reservationsInfo2.getReservationsId();
//                        } else {
//                            String selectsql = "select id from reservations_info a where a.customer_name=" + xh1s + " limit 0,1";
//                            ReservationsInfo reservationsInfo = sqlMapper.selectOne(selectsql, ReservationsInfo.class);
//                            if (reservationsInfo != null) {
//                                reservationsInfoId = reservationsInfo.getId();
//                            } else {
//
//                            }
//                        }
//                    }
                    String sql = "INSERT INTO case_info (`id`, `reservations_id`, " +
                            "`type`, `zhushu`, `now_medical_history`, " +
                            "`before_medical_history`, `mouth_check`, `auxiliary_check`, `diagnose`, " +
                            "`remedy_plan`, `dispose`, `doctor_advice`, `lable`, " +
                            "`remarkss`, `finnally_time`, `doctor_id`, `arrival_store`, `abbreviation`) VALUES " +
                            "('" + id + "' ," + xh2s + " , " + xh15s + " , " + xh4s + " " +
                            ", " + xh5s + " , " + xh6s + " , 1 " +
                            ", '2' , '3' , '4' , '5' , " + xh12s + " ," +
                            " " + xh13s + " , " + xh14s + ", " + xh3s + ", " + xh13s + " ,'乐牙店','yiya_yc_ly_');";
                    sqlMapper.insert(sql);
                    if (xh7s != null && xh7s != "" && !"null".equals(xh7s)) {
                        String count[] = xh7s.split("牙位：");
                        for (int i = 1; i < count.length; i++) {
                            String left_up = "";
                            String left_down = "";
                            String right_up = "";
                            String right_down = "";
                            if (count[i].indexOf("11,") != -1 || count[i].indexOf("11;") != -1) {
                                left_up += "1";
                            }
                            if (count[i].indexOf("12,") != -1 || count[i].indexOf("12;") != -1) {
                                left_up += "2";
                            }
                            if (count[i].indexOf("13,") != -1 || count[i].indexOf("13;") != -1) {
                                left_up += "3";
                            }
                            if (count[i].indexOf("14,") != -1 || count[i].indexOf("14;") != -1) {
                                left_up += "4";
                            }
                            if (count[i].indexOf("15,") != -1 || count[i].indexOf("15;") != -1) {
                                left_up += "5";
                            }
                            if (count[i].indexOf("16,") != -1 || count[i].indexOf("16;") != -1) {
                                left_up += "6";
                            }
                            if (count[i].indexOf("17,") != -1 || count[i].indexOf("17;") != -1) {
                                left_up += "7";
                            }
                            if (count[i].indexOf("18,") != -1 || count[i].indexOf("18;") != -1) {
                                left_up += "8";
                            }
                            if (count[i].indexOf("51,") != -1 || count[i].indexOf("51;") != -1) {
                                left_up += "A";
                            }
                            if (count[i].indexOf("52,") != -1 || count[i].indexOf("52;") != -1) {
                                left_up += "B";
                            }
                            if (count[i].indexOf("53,") != -1 || count[i].indexOf("53;") != -1) {
                                left_up += "C";
                            }
                            if (count[i].indexOf("54,") != -1 || count[i].indexOf("54;") != -1) {
                                left_up += "D";
                            }
                            if (count[i].indexOf("55,") != -1 || count[i].indexOf("55;") != -1) {
                                left_up += "E";
                            }
                            if (count[i].indexOf("21,") != -1 || count[i].indexOf("21;") != -1) {
                                right_up += "1";
                            }
                            if (count[i].indexOf("22,") != -1 || count[i].indexOf("22;") != -1) {
                                right_up += "2";
                            }
                            if (count[i].indexOf("23,") != -1 || count[i].indexOf("23;") != -1) {
                                right_up += "3";
                            }
                            if (count[i].indexOf("24,") != -1 || count[i].indexOf("24;") != -1) {
                                right_up += "4";
                            }
                            if (count[i].indexOf("25,") != -1 || count[i].indexOf("25;") != -1) {
                                right_up += "5";
                            }
                            if (count[i].indexOf("26,") != -1 || count[i].indexOf("26;") != -1) {
                                right_up += "6";
                            }
                            if (count[i].indexOf("27,") != -1 || count[i].indexOf("27;") != -1) {
                                right_up += "7";
                            }
                            if (count[i].indexOf("28,") != -1 || count[i].indexOf("28;") != -1) {
                                right_up += "8";
                            }
                            if (count[i].indexOf("61,") != -1 || count[i].indexOf("61;") != -1) {
                                right_up += "A";
                            }
                            if (count[i].indexOf("62,") != -1 || count[i].indexOf("62;") != -1) {
                                right_up += "B";
                            }
                            if (count[i].indexOf("63,") != -1 || count[i].indexOf("63;") != -1) {
                                right_up += "C";
                            }
                            if (count[i].indexOf("64,") != -1 || count[i].indexOf("64;") != -1) {
                                right_up += "D";
                            }
                            if (count[i].indexOf("65,") != -1 || count[i].indexOf("65;") != -1) {
                                right_up += "E";
                            }

                            if (count[i].indexOf("31,") != -1 || count[i].indexOf("31;") != -1) {
                                right_down += "1";
                            }
                            if (count[i].indexOf("32,") != -1 || count[i].indexOf("32;") != -1) {
                                right_down += "2";
                            }
                            if (count[i].indexOf("33,") != -1 || count[i].indexOf("33;") != -1) {
                                right_down += "3";
                            }
                            if (count[i].indexOf("34,") != -1 || count[i].indexOf("34;") != -1) {
                                right_down += "4";
                            }
                            if (count[i].indexOf("35,") != -1 || count[i].indexOf("35;") != -1) {
                                right_down += "5";
                            }
                            if (count[i].indexOf("36,") != -1 || count[i].indexOf("36;") != -1) {
                                right_down += "6";
                            }
                            if (count[i].indexOf("37,") != -1 || count[i].indexOf("37;") != -1) {
                                right_down += "7";
                            }
                            if (count[i].indexOf("38,") != -1 || count[i].indexOf("38;") != -1) {
                                right_down += "8";
                            }
                            if (count[i].indexOf("71,") != -1 || count[i].indexOf("71;") != -1) {
                                right_down += "A";
                            }
                            if (count[i].indexOf("72,") != -1 || count[i].indexOf("72;") != -1) {
                                right_down += "B";
                            }
                            if (count[i].indexOf("73,") != -1 || count[i].indexOf("73;") != -1) {
                                right_down += "C";
                            }
                            if (count[i].indexOf("74,") != -1 || count[i].indexOf("74;") != -1) {
                                right_down += "D";
                            }
                            if (count[i].indexOf("75,") != -1 || count[i].indexOf("75;") != -1) {
                                right_down += "E";
                            }

                            if (count[i].indexOf("41,") != -1 || count[i].indexOf("41;") != -1) {
                                left_down += "1";
                            }
                            if (count[i].indexOf("42,") != -1 || count[i].indexOf("42;") != -1) {
                                left_down += "2";
                            }
                            if (count[i].indexOf("43,") != -1 || count[i].indexOf("43;") != -1) {
                                left_down += "3";
                            }
                            if (count[i].indexOf("44,") != -1 || count[i].indexOf("44;") != -1) {
                                left_down += "4";
                            }
                            if (count[i].indexOf("45,") != -1 || count[i].indexOf("45;") != -1) {
                                left_down += "5";
                            }
                            if (count[i].indexOf("46,") != -1 || count[i].indexOf("46;") != -1) {
                                left_down += "6";
                            }
                            if (count[i].indexOf("47,") != -1 || count[i].indexOf("47;") != -1) {
                                left_down += "7";
                            }
                            if (count[i].indexOf("48,") != -1 || count[i].indexOf("48;") != -1) {
                                left_down += "8";
                            }
                            if (count[i].indexOf("81,") != -1 || count[i].indexOf("81;") != -1) {
                                left_down += "A";
                            }
                            if (count[i].indexOf("82,") != -1 || count[i].indexOf("82;") != -1) {
                                left_down += "B";
                            }
                            if (count[i].indexOf("83,") != -1 || count[i].indexOf("83;") != -1) {
                                left_down += "C";
                            }
                            if (count[i].indexOf("84,") != -1 || count[i].indexOf("84;") != -1) {
                                left_down += "D";
                            }
                            if (count[i].indexOf("85,") != -1 || count[i].indexOf("85;") != -1) {
                                left_down += "E";
                            }
                            if (count[i].indexOf("内容：") != -1) {
                                String remarks = count[i].split("内容：")[1].replaceAll("'", "");
                                String sql1 = "INSERT INTO `tooth_site` (`left_up`,`left_down`,`right_up`,`right_down`,`ya_wei`, `case_id`, `ya_type`, `remarks`,id2) VALUES" +
                                        "('" + left_up + "' ,'" + left_down + "' ,'" + right_up + "' ,'" + right_down + "' ,'" + count[i].split("内容：")[0].replaceAll(";", "") + "' ," +
                                        "'" + id + "' ,1,'" + remarks + "','11月19日')";
                                sqlMapper.insert(sql1);
                            }
                        }
                    }
                    if (xh8s != null && xh8s != "" && !"null".equals(xh8s)) {
                        String count[] = xh8s.split("牙位：");
                        for (int i = 1; i < count.length; i++) {
                            String left_up = "";
                            String left_down = "";
                            String right_up = "";
                            String right_down = "";
                            if (count[i].indexOf("11,") != -1 || count[i].indexOf("11;") != -1) {
                                left_up += "1";
                            }
                            if (count[i].indexOf("12,") != -1 || count[i].indexOf("12;") != -1) {
                                left_up += "2";
                            }
                            if (count[i].indexOf("13,") != -1 || count[i].indexOf("13;") != -1) {
                                left_up += "3";
                            }
                            if (count[i].indexOf("14,") != -1 || count[i].indexOf("14;") != -1) {
                                left_up += "4";
                            }
                            if (count[i].indexOf("15,") != -1 || count[i].indexOf("15;") != -1) {
                                left_up += "5";
                            }
                            if (count[i].indexOf("16,") != -1 || count[i].indexOf("16;") != -1) {
                                left_up += "6";
                            }
                            if (count[i].indexOf("17,") != -1 || count[i].indexOf("17;") != -1) {
                                left_up += "7";
                            }
                            if (count[i].indexOf("18,") != -1 || count[i].indexOf("18;") != -1) {
                                left_up += "8";
                            }
                            if (count[i].indexOf("51,") != -1 || count[i].indexOf("51;") != -1) {
                                left_up += "A";
                            }
                            if (count[i].indexOf("52,") != -1 || count[i].indexOf("52;") != -1) {
                                left_up += "B";
                            }
                            if (count[i].indexOf("53,") != -1 || count[i].indexOf("53;") != -1) {
                                left_up += "C";
                            }
                            if (count[i].indexOf("54,") != -1 || count[i].indexOf("54;") != -1) {
                                left_up += "D";
                            }
                            if (count[i].indexOf("55,") != -1 || count[i].indexOf("55;") != -1) {
                                left_up += "E";
                            }
                            if (count[i].indexOf("21,") != -1 || count[i].indexOf("21;") != -1) {
                                right_up += "1";
                            }
                            if (count[i].indexOf("22,") != -1 || count[i].indexOf("22;") != -1) {
                                right_up += "2";
                            }
                            if (count[i].indexOf("23,") != -1 || count[i].indexOf("23;") != -1) {
                                right_up += "3";
                            }
                            if (count[i].indexOf("24,") != -1 || count[i].indexOf("24;") != -1) {
                                right_up += "4";
                            }
                            if (count[i].indexOf("25,") != -1 || count[i].indexOf("25;") != -1) {
                                right_up += "5";
                            }
                            if (count[i].indexOf("26,") != -1 || count[i].indexOf("26;") != -1) {
                                right_up += "6";
                            }
                            if (count[i].indexOf("27,") != -1 || count[i].indexOf("27;") != -1) {
                                right_up += "7";
                            }
                            if (count[i].indexOf("28,") != -1 || count[i].indexOf("28;") != -1) {
                                right_up += "8";
                            }
                            if (count[i].indexOf("61,") != -1 || count[i].indexOf("61;") != -1) {
                                right_up += "A";
                            }
                            if (count[i].indexOf("62,") != -1 || count[i].indexOf("62;") != -1) {
                                right_up += "B";
                            }
                            if (count[i].indexOf("63,") != -1 || count[i].indexOf("63;") != -1) {
                                right_up += "C";
                            }
                            if (count[i].indexOf("64,") != -1 || count[i].indexOf("64;") != -1) {
                                right_up += "D";
                            }
                            if (count[i].indexOf("65,") != -1 || count[i].indexOf("65;") != -1) {
                                right_up += "E";
                            }
                            if (count[i].indexOf("31,") != -1 || count[i].indexOf("31;") != -1) {
                                right_down += "1";
                            }
                            if (count[i].indexOf("32,") != -1 || count[i].indexOf("32;") != -1) {
                                right_down += "2";
                            }
                            if (count[i].indexOf("33,") != -1 || count[i].indexOf("33;") != -1) {
                                right_down += "3";
                            }
                            if (count[i].indexOf("34,") != -1 || count[i].indexOf("34;") != -1) {
                                right_down += "4";
                            }
                            if (count[i].indexOf("35,") != -1 || count[i].indexOf("35;") != -1) {
                                right_down += "5";
                            }
                            if (count[i].indexOf("36,") != -1 || count[i].indexOf("36;") != -1) {
                                right_down += "6";
                            }
                            if (count[i].indexOf("37,") != -1 || count[i].indexOf("37;") != -1) {
                                right_down += "7";
                            }
                            if (count[i].indexOf("38,") != -1 || count[i].indexOf("38;") != -1) {
                                right_down += "8";
                            }
                            if (count[i].indexOf("71,") != -1 || count[i].indexOf("71;") != -1) {
                                right_down += "A";
                            }
                            if (count[i].indexOf("72,") != -1 || count[i].indexOf("72;") != -1) {
                                right_down += "B";
                            }
                            if (count[i].indexOf("73,") != -1 || count[i].indexOf("73;") != -1) {
                                right_down += "C";
                            }
                            if (count[i].indexOf("74,") != -1 || count[i].indexOf("74;") != -1) {
                                right_down += "D";
                            }
                            if (count[i].indexOf("75,") != -1 || count[i].indexOf("75;") != -1) {
                                right_down += "E";
                            }
                            if (count[i].indexOf("41,") != -1 || count[i].indexOf("41;") != -1) {
                                left_down += "1";
                            }
                            if (count[i].indexOf("42,") != -1 || count[i].indexOf("42;") != -1) {
                                left_down += "2";
                            }
                            if (count[i].indexOf("43,") != -1 || count[i].indexOf("43;") != -1) {
                                left_down += "3";
                            }
                            if (count[i].indexOf("44,") != -1 || count[i].indexOf("44;") != -1) {
                                left_down += "4";
                            }
                            if (count[i].indexOf("45,") != -1 || count[i].indexOf("45;") != -1) {
                                left_down += "5";
                            }
                            if (count[i].indexOf("46,") != -1 || count[i].indexOf("46;") != -1) {
                                left_down += "6";
                            }
                            if (count[i].indexOf("47,") != -1 || count[i].indexOf("47;") != -1) {
                                left_down += "7";
                            }
                            if (count[i].indexOf("48,") != -1 || count[i].indexOf("48;") != -1) {
                                left_down += "8";
                            }
                            if (count[i].indexOf("81,") != -1 || count[i].indexOf("81;") != -1) {
                                left_down += "A";
                            }
                            if (count[i].indexOf("82,") != -1 || count[i].indexOf("82;") != -1) {
                                left_down += "B";
                            }
                            if (count[i].indexOf("83,") != -1 || count[i].indexOf("83;") != -1) {
                                left_down += "C";
                            }
                            if (count[i].indexOf("84,") != -1 || count[i].indexOf("84;") != -1) {
                                left_down += "D";
                            }
                            if (count[i].indexOf("85,") != -1 || count[i].indexOf("85;") != -1) {
                                left_down += "E";
                            }
                            if (count[i].indexOf("内容：") != -1) {
                                String remarks = count[i].split("内容：")[1].replaceAll("'", "");
                                String sql1 = "INSERT INTO `tooth_site` (`left_up`,`left_down`,`right_up`,`right_down`,`ya_wei`, `case_id`, `ya_type`, `remarks`,id2) VALUES" +
                                        "('" + left_up + "' ,'" + left_down + "' ,'" + right_up + "' ,'" + right_down + "' ,'" + count[i].split("内容：")[0].replaceAll(";", "") + "' ," +
                                        "'" + id + "' ,2,'" + remarks + "','11月19日')";
                                sqlMapper.insert(sql1);
                            }
                        }
                    }
                    if (xh9s != null && xh9s != "" && !"null".equals(xh9s)) {
                        String count[] = xh9s.split("牙位：");
                        for (int i = 1; i < count.length; i++) {
                            String left_up = "";
                            String left_down = "";
                            String right_up = "";
                            String right_down = "";
                            if (count[i].indexOf("11,") != -1 || count[i].indexOf("11;") != -1) {
                                left_up += "1";
                            }
                            if (count[i].indexOf("12,") != -1 || count[i].indexOf("12;") != -1) {
                                left_up += "2";
                            }
                            if (count[i].indexOf("13,") != -1 || count[i].indexOf("13;") != -1) {
                                left_up += "3";
                            }
                            if (count[i].indexOf("14,") != -1 || count[i].indexOf("14;") != -1) {
                                left_up += "4";
                            }
                            if (count[i].indexOf("15,") != -1 || count[i].indexOf("15;") != -1) {
                                left_up += "5";
                            }
                            if (count[i].indexOf("16,") != -1 || count[i].indexOf("16;") != -1) {
                                left_up += "6";
                            }
                            if (count[i].indexOf("17,") != -1 || count[i].indexOf("17;") != -1) {
                                left_up += "7";
                            }
                            if (count[i].indexOf("18,") != -1 || count[i].indexOf("18;") != -1) {
                                left_up += "8";
                            }
                            if (count[i].indexOf("51,") != -1 || count[i].indexOf("51;") != -1) {
                                left_up += "A";
                            }
                            if (count[i].indexOf("52,") != -1 || count[i].indexOf("52;") != -1) {
                                left_up += "B";
                            }
                            if (count[i].indexOf("53,") != -1 || count[i].indexOf("53;") != -1) {
                                left_up += "C";
                            }
                            if (count[i].indexOf("54,") != -1 || count[i].indexOf("54;") != -1) {
                                left_up += "D";
                            }
                            if (count[i].indexOf("55,") != -1 || count[i].indexOf("55;") != -1) {
                                left_up += "E";
                            }

                            if (count[i].indexOf("21,") != -1 || count[i].indexOf("21;") != -1) {
                                right_up += "1";
                            }
                            if (count[i].indexOf("22,") != -1 || count[i].indexOf("22;") != -1) {
                                right_up += "2";
                            }
                            if (count[i].indexOf("23,") != -1 || count[i].indexOf("23;") != -1) {
                                right_up += "3";
                            }
                            if (count[i].indexOf("24,") != -1 || count[i].indexOf("24;") != -1) {
                                right_up += "4";
                            }
                            if (count[i].indexOf("25,") != -1 || count[i].indexOf("25;") != -1) {
                                right_up += "5";
                            }
                            if (count[i].indexOf("26,") != -1 || count[i].indexOf("26;") != -1) {
                                right_up += "6";
                            }
                            if (count[i].indexOf("27,") != -1 || count[i].indexOf("27;") != -1) {
                                right_up += "7";
                            }
                            if (count[i].indexOf("28,") != -1 || count[i].indexOf("28;") != -1) {
                                right_up += "8";
                            }
                            if (count[i].indexOf("61,") != -1 || count[i].indexOf("61;") != -1) {
                                right_up += "A";
                            }
                            if (count[i].indexOf("62,") != -1 || count[i].indexOf("62;") != -1) {
                                right_up += "B";
                            }
                            if (count[i].indexOf("63,") != -1 || count[i].indexOf("63;") != -1) {
                                right_up += "C";
                            }
                            if (count[i].indexOf("64,") != -1 || count[i].indexOf("64;") != -1) {
                                right_up += "D";
                            }
                            if (count[i].indexOf("65,") != -1 || count[i].indexOf("65;") != -1) {
                                right_up += "E";
                            }
                            if (count[i].indexOf("31,") != -1 || count[i].indexOf("31;") != -1) {
                                right_down += "1";
                            }
                            if (count[i].indexOf("32,") != -1 || count[i].indexOf("32;") != -1) {
                                right_down += "2";
                            }
                            if (count[i].indexOf("33,") != -1 || count[i].indexOf("33;") != -1) {
                                right_down += "3";
                            }
                            if (count[i].indexOf("34,") != -1 || count[i].indexOf("34;") != -1) {
                                right_down += "4";
                            }
                            if (count[i].indexOf("35,") != -1 || count[i].indexOf("35;") != -1) {
                                right_down += "5";
                            }
                            if (count[i].indexOf("36,") != -1 || count[i].indexOf("36;") != -1) {
                                right_down += "6";
                            }
                            if (count[i].indexOf("37,") != -1 || count[i].indexOf("37;") != -1) {
                                right_down += "7";
                            }
                            if (count[i].indexOf("38,") != -1 || count[i].indexOf("38;") != -1) {
                                right_down += "8";
                            }
                            if (count[i].indexOf("71,") != -1 || count[i].indexOf("71;") != -1) {
                                right_down += "A";
                            }
                            if (count[i].indexOf("72,") != -1 || count[i].indexOf("72;") != -1) {
                                right_down += "B";
                            }
                            if (count[i].indexOf("73,") != -1 || count[i].indexOf("73;") != -1) {
                                right_down += "C";
                            }
                            if (count[i].indexOf("74,") != -1 || count[i].indexOf("74;") != -1) {
                                right_down += "D";
                            }
                            if (count[i].indexOf("75,") != -1 || count[i].indexOf("75;") != -1) {
                                right_down += "E";
                            }
                            if (count[i].indexOf("41,") != -1 || count[i].indexOf("41;") != -1) {
                                left_down += "1";
                            }
                            if (count[i].indexOf("42,") != -1 || count[i].indexOf("42;") != -1) {
                                left_down += "2";
                            }
                            if (count[i].indexOf("43,") != -1 || count[i].indexOf("43;") != -1) {
                                left_down += "3";
                            }
                            if (count[i].indexOf("44,") != -1 || count[i].indexOf("44;") != -1) {
                                left_down += "4";
                            }
                            if (count[i].indexOf("45,") != -1 || count[i].indexOf("45;") != -1) {
                                left_down += "5";
                            }
                            if (count[i].indexOf("46,") != -1 || count[i].indexOf("46;") != -1) {
                                left_down += "6";
                            }
                            if (count[i].indexOf("47,") != -1 || count[i].indexOf("47;") != -1) {
                                left_down += "7";
                            }
                            if (count[i].indexOf("48,") != -1 || count[i].indexOf("48;") != -1) {
                                left_down += "8";
                            }
                            if (count[i].indexOf("81,") != -1 || count[i].indexOf("81;") != -1) {
                                left_down += "A";
                            }
                            if (count[i].indexOf("82,") != -1 || count[i].indexOf("82;") != -1) {
                                left_down += "B";
                            }
                            if (count[i].indexOf("83,") != -1 || count[i].indexOf("83;") != -1) {
                                left_down += "C";
                            }
                            if (count[i].indexOf("84,") != -1 || count[i].indexOf("84;") != -1) {
                                left_down += "D";
                            }
                            if (count[i].indexOf("85,") != -1 || count[i].indexOf("85;") != -1) {
                                left_down += "E";
                            }
                            if (count[i].indexOf("内容：") != -1) {
                                String remarks = count[i].split("内容：")[1].replaceAll("'", "");
                                String sql1 = "INSERT INTO `tooth_site` (`left_up`,`left_down`,`right_up`,`right_down`,`ya_wei`, `case_id`, `ya_type`, `remarks`,id2) VALUES" +
                                        "('" + left_up + "' ,'" + left_down + "' ,'" + right_up + "' ,'" + right_down + "' ,'" + count[i].split("内容：")[0].replaceAll(";", "") + "' ," +
                                        "'" + id + "' ,3,'" + remarks + "','11月19日')";
                                sqlMapper.insert(sql1);
                            }
                        }
                    }
                    if (xh10s != null && xh10s != "" && !"null".equals(xh10s)) {
                        String count[] = xh10s.split("牙位：");
                        for (int i = 1; i < count.length; i++) {
                            String left_up = "";
                            String left_down = "";
                            String right_up = "";
                            String right_down = "";
                            if (count[i].indexOf("11,") != -1 || count[i].indexOf("11;") != -1) {
                                left_up += "1";
                            }
                            if (count[i].indexOf("12,") != -1 || count[i].indexOf("12;") != -1) {
                                left_up += "2";
                            }
                            if (count[i].indexOf("13,") != -1 || count[i].indexOf("13;") != -1) {
                                left_up += "3";
                            }
                            if (count[i].indexOf("14,") != -1 || count[i].indexOf("14;") != -1) {
                                left_up += "4";
                            }
                            if (count[i].indexOf("15,") != -1 || count[i].indexOf("15;") != -1) {
                                left_up += "5";
                            }
                            if (count[i].indexOf("16,") != -1 || count[i].indexOf("16;") != -1) {
                                left_up += "6";
                            }
                            if (count[i].indexOf("17,") != -1 || count[i].indexOf("17;") != -1) {
                                left_up += "7";
                            }
                            if (count[i].indexOf("18,") != -1 || count[i].indexOf("18;") != -1) {
                                left_up += "8";
                            }
                            if (count[i].indexOf("51,") != -1 || count[i].indexOf("51;") != -1) {
                                left_up += "A";
                            }
                            if (count[i].indexOf("52,") != -1 || count[i].indexOf("52;") != -1) {
                                left_up += "B";
                            }
                            if (count[i].indexOf("53,") != -1 || count[i].indexOf("53;") != -1) {
                                left_up += "C";
                            }
                            if (count[i].indexOf("54,") != -1 || count[i].indexOf("54;") != -1) {
                                left_up += "D";
                            }
                            if (count[i].indexOf("55,") != -1 || count[i].indexOf("55;") != -1) {
                                left_up += "E";
                            }
                            if (count[i].indexOf("21,") != -1 || count[i].indexOf("21;") != -1) {
                                right_up += "1";
                            }
                            if (count[i].indexOf("22,") != -1 || count[i].indexOf("22;") != -1) {
                                right_up += "2";
                            }
                            if (count[i].indexOf("23,") != -1 || count[i].indexOf("23;") != -1) {
                                right_up += "3";
                            }
                            if (count[i].indexOf("24,") != -1 || count[i].indexOf("24;") != -1) {
                                right_up += "4";
                            }
                            if (count[i].indexOf("25,") != -1 || count[i].indexOf("25;") != -1) {
                                right_up += "5";
                            }
                            if (count[i].indexOf("26,") != -1 || count[i].indexOf("26;") != -1) {
                                right_up += "6";
                            }
                            if (count[i].indexOf("27,") != -1 || count[i].indexOf("27;") != -1) {
                                right_up += "7";
                            }
                            if (count[i].indexOf("28,") != -1 || count[i].indexOf("28;") != -1) {
                                right_up += "8";
                            }
                            if (count[i].indexOf("61,") != -1 || count[i].indexOf("61;") != -1) {
                                right_up += "A";
                            }
                            if (count[i].indexOf("62,") != -1 || count[i].indexOf("62;") != -1) {
                                right_up += "B";
                            }
                            if (count[i].indexOf("63,") != -1 || count[i].indexOf("63;") != -1) {
                                right_up += "C";
                            }
                            if (count[i].indexOf("64,") != -1 || count[i].indexOf("64;") != -1) {
                                right_up += "D";
                            }
                            if (count[i].indexOf("65,") != -1 || count[i].indexOf("65;") != -1) {
                                right_up += "E";
                            }
                            if (count[i].indexOf("31,") != -1 || count[i].indexOf("31;") != -1) {
                                right_down += "1";
                            }
                            if (count[i].indexOf("32,") != -1 || count[i].indexOf("32;") != -1) {
                                right_down += "2";
                            }
                            if (count[i].indexOf("33,") != -1 || count[i].indexOf("33;") != -1) {
                                right_down += "3";
                            }
                            if (count[i].indexOf("34,") != -1 || count[i].indexOf("34;") != -1) {
                                right_down += "4";
                            }
                            if (count[i].indexOf("35,") != -1 || count[i].indexOf("35;") != -1) {
                                right_down += "5";
                            }
                            if (count[i].indexOf("36,") != -1 || count[i].indexOf("36;") != -1) {
                                right_down += "6";
                            }
                            if (count[i].indexOf("37,") != -1 || count[i].indexOf("37;") != -1) {
                                right_down += "7";
                            }
                            if (count[i].indexOf("38,") != -1 || count[i].indexOf("38;") != -1) {
                                right_down += "8";
                            }
                            if (count[i].indexOf("71,") != -1 || count[i].indexOf("71;") != -1) {
                                right_down += "A";
                            }
                            if (count[i].indexOf("72,") != -1 || count[i].indexOf("72;") != -1) {
                                right_down += "B";
                            }
                            if (count[i].indexOf("73,") != -1 || count[i].indexOf("73;") != -1) {
                                right_down += "C";
                            }
                            if (count[i].indexOf("74,") != -1 || count[i].indexOf("74;") != -1) {
                                right_down += "D";
                            }
                            if (count[i].indexOf("75,") != -1 || count[i].indexOf("75;") != -1) {
                                right_down += "E";
                            }
                            if (count[i].indexOf("41,") != -1 || count[i].indexOf("41;") != -1) {
                                left_down += "1";
                            }
                            if (count[i].indexOf("42,") != -1 || count[i].indexOf("42;") != -1) {
                                left_down += "2";
                            }
                            if (count[i].indexOf("43,") != -1 || count[i].indexOf("43;") != -1) {
                                left_down += "3";
                            }
                            if (count[i].indexOf("44,") != -1 || count[i].indexOf("44;") != -1) {
                                left_down += "4";
                            }
                            if (count[i].indexOf("45,") != -1 || count[i].indexOf("45;") != -1) {
                                left_down += "5";
                            }
                            if (count[i].indexOf("46,") != -1 || count[i].indexOf("46;") != -1) {
                                left_down += "6";
                            }
                            if (count[i].indexOf("47,") != -1 || count[i].indexOf("47;") != -1) {
                                left_down += "7";
                            }
                            if (count[i].indexOf("48,") != -1 || count[i].indexOf("48;") != -1) {
                                left_down += "8";
                            }
                            if (count[i].indexOf("81,") != -1 || count[i].indexOf("81;") != -1) {
                                left_down += "A";
                            }
                            if (count[i].indexOf("82,") != -1 || count[i].indexOf("82;") != -1) {
                                left_down += "B";
                            }
                            if (count[i].indexOf("83,") != -1 || count[i].indexOf("83;") != -1) {
                                left_down += "C";
                            }
                            if (count[i].indexOf("84,") != -1 || count[i].indexOf("84;") != -1) {
                                left_down += "D";
                            }
                            if (count[i].indexOf("85,") != -1 || count[i].indexOf("85;") != -1) {
                                left_down += "E";
                            }
                            if (count[i].indexOf("内容：") != -1) {
                                String remarks = count[i].split("内容：")[1].replaceAll("'", "");
                                String sql1 = "INSERT INTO `tooth_site` (`left_up`,`left_down`,`right_up`,`right_down`,`ya_wei`, `case_id`, `ya_type`, `remarks`,id2) VALUES" +
                                        "('" + left_up + "' ,'" + left_down + "' ,'" + right_up + "' ,'" + right_down + "' ,'" + count[i].split("内容：")[0].replaceAll(";", "") + "' ," +
                                        "'" + id + "' ,4,'" + remarks + "','11月19日')";
                                sqlMapper.insert(sql1);
                            }
                        }
                    }
                    if (xh11s != null && xh11s != "" && !"null".equals(xh11s)) {
                        String count[] = xh11s.split("牙位：");
                        for (int i = 1; i < count.length; i++) {
                            String left_up = "";
                            String left_down = "";
                            String right_up = "";
                            String right_down = "";
                            if (count[i].indexOf("11,") != -1 || count[i].indexOf("11;") != -1) {
                                left_up += "1";
                            }
                            if (count[i].indexOf("12,") != -1 || count[i].indexOf("12;") != -1) {
                                left_up += "2";
                            }
                            if (count[i].indexOf("13,") != -1 || count[i].indexOf("13;") != -1) {
                                left_up += "3";
                            }
                            if (count[i].indexOf("14,") != -1 || count[i].indexOf("14;") != -1) {
                                left_up += "4";
                            }
                            if (count[i].indexOf("15,") != -1 || count[i].indexOf("15;") != -1) {
                                left_up += "5";
                            }
                            if (count[i].indexOf("16,") != -1 || count[i].indexOf("16;") != -1) {
                                left_up += "6";
                            }
                            if (count[i].indexOf("17,") != -1 || count[i].indexOf("17;") != -1) {
                                left_up += "7";
                            }
                            if (count[i].indexOf("18,") != -1 || count[i].indexOf("18;") != -1) {
                                left_up += "8";
                            }
                            if (count[i].indexOf("51,") != -1 || count[i].indexOf("51;") != -1) {
                                left_up += "A";
                            }
                            if (count[i].indexOf("52,") != -1 || count[i].indexOf("52;") != -1) {
                                left_up += "B";
                            }
                            if (count[i].indexOf("53,") != -1 || count[i].indexOf("53;") != -1) {
                                left_up += "C";
                            }
                            if (count[i].indexOf("54,") != -1 || count[i].indexOf("54;") != -1) {
                                left_up += "D";
                            }
                            if (count[i].indexOf("55,") != -1 || count[i].indexOf("55;") != -1) {
                                left_up += "E";
                            }
                            if (count[i].indexOf("21,") != -1 || count[i].indexOf("21;") != -1) {
                                right_up += "1";
                            }
                            if (count[i].indexOf("22,") != -1 || count[i].indexOf("22;") != -1) {
                                right_up += "2";
                            }
                            if (count[i].indexOf("23,") != -1 || count[i].indexOf("23;") != -1) {
                                right_up += "3";
                            }
                            if (count[i].indexOf("24,") != -1 || count[i].indexOf("24;") != -1) {
                                right_up += "4";
                            }
                            if (count[i].indexOf("25,") != -1 || count[i].indexOf("25;") != -1) {
                                right_up += "5";
                            }
                            if (count[i].indexOf("26,") != -1 || count[i].indexOf("26;") != -1) {
                                right_up += "6";
                            }
                            if (count[i].indexOf("27,") != -1 || count[i].indexOf("27;") != -1) {
                                right_up += "7";
                            }
                            if (count[i].indexOf("28,") != -1 || count[i].indexOf("28;") != -1) {
                                right_up += "8";
                            }
                            if (count[i].indexOf("61,") != -1 || count[i].indexOf("61;") != -1) {
                                right_up += "A";
                            }
                            if (count[i].indexOf("62,") != -1 || count[i].indexOf("62;") != -1) {
                                right_up += "B";
                            }
                            if (count[i].indexOf("63,") != -1 || count[i].indexOf("63;") != -1) {
                                right_up += "C";
                            }
                            if (count[i].indexOf("64,") != -1 || count[i].indexOf("64;") != -1) {
                                right_up += "D";
                            }
                            if (count[i].indexOf("65,") != -1 || count[i].indexOf("65;") != -1) {
                                right_up += "E";
                            }
                            if (count[i].indexOf("31,") != -1 || count[i].indexOf("31;") != -1) {
                                right_down += "1";
                            }
                            if (count[i].indexOf("32,") != -1 || count[i].indexOf("32;") != -1) {
                                right_down += "2";
                            }
                            if (count[i].indexOf("33,") != -1 || count[i].indexOf("33;") != -1) {
                                right_down += "3";
                            }
                            if (count[i].indexOf("34,") != -1 || count[i].indexOf("34;") != -1) {
                                right_down += "4";
                            }
                            if (count[i].indexOf("35,") != -1 || count[i].indexOf("35;") != -1) {
                                right_down += "5";
                            }
                            if (count[i].indexOf("36,") != -1 || count[i].indexOf("36;") != -1) {
                                right_down += "6";
                            }
                            if (count[i].indexOf("37,") != -1 || count[i].indexOf("37;") != -1) {
                                right_down += "7";
                            }
                            if (count[i].indexOf("38,") != -1 || count[i].indexOf("38;") != -1) {
                                right_down += "8";
                            }
                            if (count[i].indexOf("71,") != -1 || count[i].indexOf("71;") != -1) {
                                right_down += "A";
                            }
                            if (count[i].indexOf("72,") != -1 || count[i].indexOf("72;") != -1) {
                                right_down += "B";
                            }
                            if (count[i].indexOf("73,") != -1 || count[i].indexOf("73;") != -1) {
                                right_down += "C";
                            }
                            if (count[i].indexOf("74,") != -1 || count[i].indexOf("74;") != -1) {
                                right_down += "D";
                            }
                            if (count[i].indexOf("75,") != -1 || count[i].indexOf("75;") != -1) {
                                right_down += "E";
                            }
                            if (count[i].indexOf("41,") != -1 || count[i].indexOf("41;") != -1) {
                                left_down += "1";
                            }
                            if (count[i].indexOf("42,") != -1 || count[i].indexOf("42;") != -1) {
                                left_down += "2";
                            }
                            if (count[i].indexOf("43,") != -1 || count[i].indexOf("43;") != -1) {
                                left_down += "3";
                            }
                            if (count[i].indexOf("44,") != -1 || count[i].indexOf("44;") != -1) {
                                left_down += "4";
                            }
                            if (count[i].indexOf("45,") != -1 || count[i].indexOf("45;") != -1) {
                                left_down += "5";
                            }
                            if (count[i].indexOf("46,") != -1 || count[i].indexOf("46;") != -1) {
                                left_down += "6";
                            }
                            if (count[i].indexOf("47,") != -1 || count[i].indexOf("47;") != -1) {
                                left_down += "7";
                            }
                            if (count[i].indexOf("48,") != -1 || count[i].indexOf("48;") != -1) {
                                left_down += "8";
                            }
                            if (count[i].indexOf("81,") != -1 || count[i].indexOf("81;") != -1) {
                                left_down += "A";
                            }
                            if (count[i].indexOf("82,") != -1 || count[i].indexOf("82;") != -1) {
                                left_down += "B";
                            }
                            if (count[i].indexOf("83,") != -1 || count[i].indexOf("83;") != -1) {
                                left_down += "C";
                            }
                            if (count[i].indexOf("84,") != -1 || count[i].indexOf("84;") != -1) {
                                left_down += "D";
                            }
                            if (count[i].indexOf("85,") != -1 || count[i].indexOf("85;") != -1) {
                                left_down += "E";
                            }
                            if (count[i].indexOf("内容：") != -1) {
                                String remarks = count[i].split("内容：")[1].replaceAll("'", "");
                                String sql1 = "INSERT INTO `tooth_site` (`left_up`,`left_down`,`right_up`,`right_down`,`ya_wei`, `case_id`, `ya_type`, `remarks`,id2) VALUES" +
                                        "('" + left_up + "' ,'" + left_down + "' ,'" + right_up + "' ,'" + right_down + "' ,'" + count[i].split("内容：")[0].replaceAll(";", "") + "' ," +
                                        "'" + id + "' ,5,'" + remarks + "','11月19日')";
                                sqlMapper.insert(sql1);
                            }
                        }
                    }
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
            return "/testClose.html";
        } else {
            return "/testClose.html";
        }
    }


    @RequestMapping(value = "/doctorExport")
    public void reservationsExport(@RequestParam(required = false) String reach,
                                   @RequestParam(required = false) String arrivalStore,
                                   @RequestParam(required = false) String startCreateTime,
                                   @RequestParam(required = false) String endCreateTime,
                                   @RequestParam(required = false) String fieldTc,
                                   @RequestParam(required = false) String appointmentPayService,
                                   @RequestParam(required = false) String treatmentUnit,
                                   @RequestParam(required = false) String doctor,
                                   @RequestParam(required = false) String dimensionSelection,
                                   HttpServletResponse response) {
        try {
            SearchDoctorChangePriceInfo searchInfo = new SearchDoctorChangePriceInfo();
            searchInfo.setReach(reach);
            searchInfo.setFieldTc(fieldTc);
            searchInfo.setStartCreateTime(startCreateTime);
            searchInfo.setEndCreateTime(endCreateTime);
            searchInfo.setArrivalStore(arrivalStore);
            searchInfo.setAppointmentPayService(appointmentPayService);
            searchInfo.setTreatmentUnit(treatmentUnit);
            searchInfo.setDoctor(doctor);
            searchInfo.setDimensionSelection(dimensionSelection);
            List<DoctorChangePriceInfo> list = service.customerExport(searchInfo);
            // 解析成excel文件
            // 第一步,创建一个webbook,对应一个Excel文件
            HSSFWorkbook wb = new HSSFWorkbook();
            // 第二步,在wb中添加一个sheet,对应Excel文件中的sheet
            HSSFSheet sheet = wb.createSheet("前端导出");
            for (int i = 0; i < 20; i++) {
                sheet.setColumnWidth(i, 24 * 256);
            }
            // 第三步,在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制short
            HSSFRow row = sheet.createRow(0);
            // 第四步,创建单元格,并设置值表头 设置表头居中
            HSSFCellStyle style = wb.createCellStyle();
            style.setAlignment(HorizontalAlignment.CENTER);// 创建一个居中格式
            HSSFCell cell = row.createCell(0);
            cell.setCellValue("病历号");
            cell.setCellStyle(style);
            cell = row.createCell(1);
            cell.setCellValue("门店");
            cell.setCellStyle(style);
            cell = row.createCell(2);
            cell.setCellValue("医生");
            cell.setCellStyle(style);
            cell = row.createCell(3);
            cell.setCellValue("TC");
            cell.setCellStyle(style);
            cell = row.createCell(4);
            cell.setCellValue("客户姓名");
            cell.setCellStyle(style);
            cell = row.createCell(5);
            cell.setCellValue("性别");
            cell.setCellStyle(style);
            cell = row.createCell(6);
            cell.setCellValue("年龄");
            cell.setCellStyle(style);
            cell = row.createCell(7);
            cell.setCellValue("执行时间");
            cell.setCellStyle(style);
            cell = row.createCell(8);
            cell.setCellValue("科室");
            cell.setCellStyle(style);
            cell = row.createCell(9);
            cell.setCellValue("项目");
            cell.setCellStyle(style);
            cell = row.createCell(10);
            cell.setCellValue("数量");
            cell.setCellStyle(style);
            cell = row.createCell(11);
            cell.setCellValue("总业绩");
            cell.setCellStyle(style);
            cell = row.createCell(12);
            cell.setCellValue("执行业绩");
            cell.setCellStyle(style);
            cell = row.createCell(13);
            cell.setCellValue("实收");
            cell.setCellStyle(style);
            cell = row.createCell(14);
            cell.setCellValue("抵扣");
            cell.setCellStyle(style);


            // 填充数据
            for (int i = 0; i < list.size(); i++) {
                DoctorChangePriceInfo map = list.get(i);
                row = sheet.createRow(i + 1);
                String customerName = "";
                if (map.getCustomerName() != null) {
                    customerName = map.getCustomerName();
                }
                String sex = map.getSex();
                int customerAge = 0;
                if (map.getCustomerAge() != null) {
                    customerAge = map.getCustomerAge();
                }
                int number = 0;
                if (map.getNumber() != null) {
                    number = map.getNumber();
                }
                String medicalRecordNumber = map.getMedicalRecordNumber();
                appointmentPayService = map.getAppointmentPayService();
                arrivalStore = map.getArrivalStore();
                treatmentUnit = map.getTreatmentUnit();
                String createTime = map.getCreateTime();

                sex = map.getSex();
                if (map.getCustomerAge() != null) {
                    customerAge = map.getCustomerAge();
                }
                fieldTc = map.getFieldTc();
                doctor = map.getDoctor();

                Double serviceActualPayS = map.getServiceActualPayS();
                if (StringUtil.isEmpty(serviceActualPayS)) {
                    serviceActualPayS = 0.00;
                }
                Double perAccount = map.getPerAccount();
                if (StringUtil.isEmpty(perAccount)) {
                    perAccount = 0.00;
                }
                Double totalServiceActualPay = map.getTotalServiceActualPay();
                if (StringUtil.isEmpty(totalServiceActualPay)) {
                    totalServiceActualPay = 0.00;
                }
                Double deduction = map.getDeduction();
                if (StringUtil.isEmpty(deduction)) {
                    deduction = 0.00;
                }
                Integer id = map.getId();
                // 第四步,创建单元格,并设置值
                for (int j = 0; j <= 14; j++) {
                    row.createCell(j).setCellStyle(style);
                }
//                row.getCell(0).setCellValue(customerStatus);
                row.getCell(0).setCellValue(medicalRecordNumber);
                row.getCell(1).setCellValue(arrivalStore);
                row.getCell(2).setCellValue(doctor);
                row.getCell(3).setCellValue(fieldTc);
                row.getCell(4).setCellValue(customerName);
                row.getCell(5).setCellValue(sex);
                row.getCell(6).setCellValue(customerAge);
                row.getCell(7).setCellValue(createTime);
                row.getCell(8).setCellValue(treatmentUnit);
                row.getCell(9).setCellValue(appointmentPayService);
                row.getCell(10).setCellValue(number);
                row.getCell(11).setCellValue(totalServiceActualPay);
                row.getCell(12).setCellValue(serviceActualPayS);
                row.getCell(13).setCellValue(perAccount);
                row.getCell(14).setCellValue(deduction);
            }
            String date = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new java.util.Date());
            String filename = "data" + date + ".xls";
            response.setHeader("Content-Disposition",
                    "attachment; filename=\"" + URLEncoder.encode(filename, "UTF-8") + "\"");
            response.setContentType("application/octet-stream;charset=UTF-8");
            OutputStream outputStream = new BufferedOutputStream(response.getOutputStream());
            wb.write(outputStream);
            outputStream.flush();
            outputStream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @RequestMapping(value = "/weiXin_uploadIcon", method = RequestMethod.POST)
    @ResponseBody
    public void weiXin_uploadIcon(String finnallyTime, String[] src,
                                  String reservationsId, String customerId, String payServiceId, String iconType, String
                                          remarks, HttpServletRequest request) {
        for (int i = 0; i < src.length; i++) {
            String base64Data = src[i].split(",")[1];
            Base64.Decoder decoder = Base64.getDecoder();
            byte[] bytes = decoder.decode(base64Data);
            FileOutputStream fos = null;
            try {
                /* 找出指定的2个字符在 该字符串里面的 位置 */
                int strStartIndex = src[i].indexOf("/") + 1;
                int strEndIndex = src[i].indexOf(";");
                /* 开始截取 */
                String hz = src[i].substring(strStartIndex, strEndIndex);
                String iconName = bytes.toString() + "." + hz;
                fos = new FileOutputStream("D:\\8068\\apache-tomcat-8.0.30\\webapps\\ROOT\\yingxiang\\" + iconName + "");
                fos.write(bytes);  //写入文件
                String httpUrl = "http://118.123.15.60:8068/yingxiang/" + iconName;
                String alldiagnose2 = finnallyTime + " " + ShiroKit.getUser().getOutpatientName();
                String sql = "insert into  icon_info (customer_id,reservations_id,outpatient_name,add_name," +
                        "add_time,image_url,icon_name,remarks,diagnoseTime,pay_service_id) values ('" + customerId
                        + "','" + reservationsId + "','" + ShiroKit.getUser().getOutpatientName() + "','"
                        + ShiroKit.getUser().getAccount() + "','" + DateTimeKit.now() + "','" + httpUrl
                        + "','" + iconType + "','" + remarks + "','" + alldiagnose2 + "','" + payServiceId + "')";
                sqlMapper.insert(sql);
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                if (fos != null) {
                    try {
                        fos.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}